How to Check if Element is Exists or not in jQuery?

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this post i will show you How to Check if Element is Exists or not in jQuery? Most of the time you have need to check specific element is exists or not in javascript. We know jquery provide us a length() method that can help us to check the element is exists or not. If you are new and if you want to do this then let’s start and see the 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>

Read Also : How to convert Object into Array in PHP?

Thanks for read. I hope it help you. For more you can follow us on facebook.

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →