How to check if an element exists in jQuery?
When we use dynamic elements in jQuery then sometimes you should check whether elements exits or not before performing a certain action on that element. In such cases, you can use jQuery .length property to determine if your selector matched anything in the webpage.

Div selector with ID
Div selector with Class
Full Source
jQuery show() method
In jQuery , it isn't always necessary to test whether an element exists or not . The following code will show the element if it exists, and do nothing (with no errors) if it does not exists.
Javascript
In JavaScript, you can use the following JavaScript to test whether an element exists or not.