if exists in JS and jQuery


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.