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 are selectors in jquery? Explain
Explain chaining in jquery? : jquery mobile
How to get the direct parent of an element using ?
How to disable/enable an element with jQuery?
Explain the difference between parent() and parents() methods in jquery? : jquery mobile
Explain the term method chaining? : jQuery Mobile
Hide and show image on button click using jQuery?
Explain url paremeter of jquery ajax method?
How does jquery mobile theming work? : jquery mobile
Define the script build up by jquery?
What is the latest version of jquery?
Explain the basic need to start with jquery? : jquery mobile