jQuery check dom element exists in page

Here I am going to explain how to check or validate DOM element exists in a page or not.

we used to check DOM element existence like jQuery(‘#ID’) or jQuery(‘.Class’) but keep in mind jQuery always return array weather DOM element exists or not. If not exists then it returns blank array so we must check array length to know is array has element or not.


// wrong way

// Correct way

Leave a Reply

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