DEV Community

loading...
Cover image for Use jQuery to see if an element exists

Use jQuery to see if an element exists

Adam K Dean
Blockchain Lead. Hacker. Founder. Amateur Radio, and all things engineering.
・1 min read

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.

Discussion (0)