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

Use jQuery to see if an element exists

adamkdean profile image Adam K Dean ・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;

Probably the shortest snippet so far.

Discussion

markdown guide