How do you check if an element is empty?



How do you check if an element is empty?..

Answer / chaitanya

There are 2 ways to check if element is empty or not. We can check using ":empty" selector.

Hide Copy Code

$(document).ready(function(){

if ($('#element').is(':empty')){

//Element is empty

}

});

And the second way is using the "$.trim()" method.

Hide Copy Code

$(document).ready(function(){

if($.trim($('#element').html())=='') {

//Element is empty

}

});

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More jQuery Interview Questions

What is the difference between size and length of jQuery?

0 Answers  


List the advantages of jquery?

0 Answers  


Define jquery filter?

0 Answers  


How do you add an HTML element in DOM tree?

0 Answers  


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

1 Answers  






How does jquery mobile theming work? : jquery mobile

0 Answers  


How to use jquery library in our asp.net project?

0 Answers  


Explain the difference between javascript and jquery? : jquery mobile

0 Answers  


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

0 Answers  


How to create clone of any object using jQuery?

1 Answers  


Tell me can we have multiple document.ready() function on the same page? : jquery mobile

0 Answers  


What are all the ways to include jQuery in a page?

0 Answers  


Categories