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

Why we use jquery .each() function?

0 Answers  


Explain .siblings() method in jquery?

0 Answers  


How we can hide a block of html code on a button click using jquery?

0 Answers  


Explain width() vs css(‘width’)?

0 Answers  


How to programmatically trigger a click event thats being handled by jquery only?

0 Answers  






What is a use of jquery filter?

0 Answers  


How to get the value of selected option in jquery?

0 Answers  


Name some of the methods of jquery used to provide effects?

0 Answers  


Difference Between Prop and Attr in jQuery?

0 Answers  


Where jQuery code is getting executed?

0 Answers  


How to use jquery?

0 Answers  


Why should I use jquery?

0 Answers  


Categories