How to Check If Element is Exists or Not in jQuery?

By Hardik Savani April 6, 2023 Category : jQuery

Hi guys,

In this article, we will discuss how to check if an element exists in jQuery. We will provide a detailed guide on how to check if an element exists or not using jQuery. Additionally, we will demonstrate how to check if an element exists using jQuery.

If you are interested in seeing an example of how to check if a class exists on a page using jQuery, then you have come to the right place.

Most of the time we require to check specific element is exists or not in javascript. but jquery provide length() method that can help to check element is exists or not. If you are new and want to do this then see bellow example:

Example:

<script type="text/javascript">

$(document).ready(function(){

if ($('.image').length) {

console.log('yes, Image class is exists.');

} else {

console.log('sorry, Image class is not exists.');

}

});

</script>

Tags :
Shares