DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Use jQuery to see if an element exists
Adam K Dean
Adam K Dean

Posted on

Use jQuery to see if an element exists

You can use jQuery to see if an element exists by checking if the length of the jQuery object is > zero.

var exists = $('.your-selector-here').length > 0;
Enter fullscreen mode Exit fullscreen mode

Probably the shortest snippet so far.

Top comments (0)

Find what you were looking for? Sign up so you can:

Β 
🌚 Enable dark mode
πŸ”  Change your default font
πŸ“š Adjust your experience level to see more relevant content