16 June 2011

This snippet shows how to check if jQuery selector exists.

Source code viewer
  1. if ($(selector).length) {
  2. // if selector exists do these things
  3. }
  4.  
  5. if (!$(selector).length) {
  6. // if selector does not exist do these things
  7. }
Programming Language: jQuery