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 |
How do I check if an element is hidden in jQuery?
What is the difference between jquery and javascript?
Explain all the ways to include jquery in a page?
Explain .siblings() method in jquery?
What is the use of noconflict() method in jquery?
What is jquery and what are the advantages?
Is jQuery is a replacement of JavaScript?
What is the difference between onload() and document.ready() function used in jquery?
What is the use of clone method in jQuery?
How does caching helps and how to use caching in jQuery?
What are selectors in jquery mean ?
How can events be prevented to work after an ajax request?