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)