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

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

1 Answers  


How do you update ajax response with id " resilts"?

0 Answers  


What are features of jquery or what can be done using jquery?

0 Answers  


Which are the fastest selectors in jquery? : jquery mobile

0 Answers  


What is the difference between settimeout() and setinterval() methods?

0 Answers  






Mention the advantages of cdn? : jQuery Mobile

0 Answers  


What is jQuery?

1 Answers  


Can we select a element having a specific class in jquery ?

0 Answers  


What is the difference between onload() and document.ready()?

0 Answers  


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

0 Answers  


How to divide a page into parts using jquery mobile? : jquery mobile

0 Answers  


Explain the advantages of jquery?

0 Answers  


Categories