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

How can you select all elements in a page using jquery?

628


Mention the differences between javascript and jquery.

594


How to get the style property of an element using ?

570


How To Use Ajax In Jquery?

615


Difference between document.ready and window.onload? : jQuery Mobile

669


How to execute jQuery code after the DOM is ready?

642


What are the slow selectors in jquery? : jquery mobile

605


Define type paremeter of jquery ajax method?

592


Explain slidetoggle() effect.

665


Need to add jQuery file in both Master and Content page?

618


How can we include jQuery library in ASP.Net project?

644


What is a cdn? : jQuery Mobile

673


Is jquery still relevant 2019?

698


Can you use multiple document.ready() function on the same page?

720


In what scenarios jQuery can be used?

697