How do you check if an element exists or not in jQuery?



How do you check if an element exists or not in jQuery?..

Answer / chaitanya

Using jQuery length property, we can ensure whether element exists or not.

Hide Copy Code

$(document).ready(function(){

if ($('#element').length > 0){

//Element exists

}

});

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More jQuery Interview Questions

explain width() vs css(‘width’) in jquery

0 Answers  


What is the use of css() method in jquery?

0 Answers  


How to programmatically trigger a click event that's being handled by jquery?

0 Answers  


How does the jQuery pushStack function work?

0 Answers  


What features of jquery, has been used in web applications?

0 Answers  






What is the use of toggle() method in jquery?

0 Answers  


How to multiple version of jQuery?

0 Answers  


Why jQuery is better than JavaScript?

0 Answers  


​ What is difference between prop and attr?

1 Answers  


How does caching helps and how to use caching in jQuery?

1 Answers  


Write a code for the implementation of a module pattern.

0 Answers  


Is it possible to get value of multiple CSS properties in single statement?

1 Answers  


Categories