Posted By

cesarkohl on 09/13/11


Tagged

javascript jquery length exists if


Versions (?)

if exists in JS and jQuery


 / Published in: JavaScript
 

How to know if an element exists in JS (and jQuery).

  1. // Pure JavaScript
  2. if(document.getElementById('example').length == 0){} // no element found
  3.  
  4. // jQuery
  5. if($('element').length == 0){} // no element found

Report this snippet  

You need to login to post a comment.