How to Check if an element exists in jQuery

How to Check if an element exists in jQuery : You can use .length method in jquery to check if an element exist. It returns length > 0 if an element exist else it will return false. This becomes very useful when you are working with dynamic content.

Syntax to Check if an element exists in jQuery

Here is An Example to check the solution for this problem –

function checkElement() {
if( $('#slector'>).length >0)       
{
    alert("element exists");
}
else{

alert("element does not exist");
}
}

In the above example we have created function to check element exists or not.


Advertisements

Add Comment

📖 Read More