Home Is there an "exists" function for jQuery?

# Is there an "exists" function for jQuery?

user4858
1#
user4858 Published in September 19, 2018, 6:44 pm

How can I check the existence of an element in jQuery?

The current code that I have is this:

if (\$(selector).length > 0) {
// Do something
}


Is there a more elegant way to approach this? Perhaps a plugin or a function?