Back
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 }
if ($(selector).length > 0) {
// Do something
}
Is there a more elegant way to approach this? Perhaps a plugin or a function?
For checking the existence of an element in jQuery you can use the below mentioned piece of code:
if ($(selector).length)
Want to become a Web Developer, join Web Development Courses now!
31k questions
32.8k answers
501 comments
693 users