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 |
what does $("div") will select? : jquery mobile
Which version of jquery file should be used?
What is jquery and what are the advantages?
Define "beforesend(xhr)" paremeter of jquery ajax method?
Explain jquery $.ajax() method?
How to read cookies in jquery?
Does events are also copied when you clone any element in jQuery?
When can jquery be used?
Why are not some scripts and styles loading? : jquery mobile
How to keep the submit text from showing with jquery mobile? : jquery mobile
What is queue() in jquery? Use of queue() in jquery?
Tell me how to check data type of any variable in jquery? : jquery mobile