How to check some element for existing

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

Copy this code and paste it in your HTML
  1. /*The .length property in jQuery returns the length
  2. or number of elements inside an array or the string
  3. length. If you want to check the existence of the
  4. element, just check if the returned value of length
  5. is zero:*/
  7. if ($(selector).length)
  8. {
  9. //your code here
  10. }

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.