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


You need to login to view comments.