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

By Hardik Savani | April 13, 2016 | | 31012 Viewer | Category : Javascript jQuery


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>




Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.