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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between prop() and attr() in jquery?

438


How can events be prevented to work after an ajax request?

438


Can you write a code to select all links inside the paragraph?

516


What is difference between sorting string array and sorting numerical array in jquery?

467


Create a plugin that would add and remove a class on hover.

434






How we can check if an element is empty or not using jquery?

446


How to run an event handler only once in jQuery?

504


Whether we need to add jQuery file in both Master and Content page?

454


What is the use of jQuery filter?

466


How to stop jqm from auto-enhancing an element? : jquery mobile

440


What is the use of jquery.data()?

470


Define type paremeter of jquery ajax method?

435


What is cdn and how jquery is related to it?

466


What is jquery.size()? : jquery mobile

469


Explain deferred and promise object in jquery? : jquery mobile

455