check if an element exists? - Javascript jQuery

Javascript examples for jQuery:Tag Traversing

Description

check if an element exists?

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.5.2.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*www .ja  va2s . c om*/

$('div').length ? console.log('div found') : console.log('Div not found')

    });

      </script> 
 </head> 
 <body> 
  <div></div> 
  <p></p>  
 </body>
</html>

Related Tutorials