Using JavaScript write a boolean method that returns true if

Using JavaScript write a boolean method that returns true if an element is rendered on a page
Using JavaScript write a boolean method that returns true if an element is rendered on a page

Solution

<html>
<head>  
   <script>
       var variable_name = 1;
       alert(getBoolean());
       function getBoolean()
       {
           if (typeof variable_name != \'undefined\')return true;
           else return false;
       }
   </script>
</head>
<body>
</body>
</html>

In order to search for a HTML element on page, following options can be used.

For example, to check whether a <div> with id=\"abc\" is rendered by the browser or not, following script can be used.

<html>
<head>  
  
</head>
<body>
<div id=\"abc\"></div>

<script>
       function getBoolean(arg)
       {
           if (document.getElementById(arg) !=null)
               alert(\'it exists!\');

           if (document.getElementById(arg) ==null)
               alert(\'does not exist!\');

       }
       getBoolean(\"abc\");
   </script>
</body>
</html>

 Using JavaScript write a boolean method that returns true if an element is rendered on a page Using JavaScript write a boolean method that returns true if an e

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site