Check whether an Element Exists using JQuery

In JavaScript to check whether an element exist or not we can use something like this

jquery element exists

But in case of jQuery to check an element exist or not the code can be written like this

We can also leave the >0 and the code will simply look like this

In the code above we are using length property of the jQuery collection returned by selector.

To display the element if exist use the show() method, the complete code will look like this

so as we can see that jQuery make the code a bit shorter than javascript.

One Comment to “Check whether an Element Exists using JQuery”

Leave a Reply

Your email address will not be published. Required fields are marked *