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 the guidelines for an application to follow the principles of progressive enhancement.
How you will use jquery means requirement needed for using jquery.
What is the difference between jquery and javascript?
What is the difference between settimeout() and setinterval() methods?
Whether C# code behind can be called from jQuery?
How can an element be checked if it contains a specific class?
Is it possible to use our own specific character in the place of $ sign in jquery? : jquery mobile
Explain the difference between onload() and document.ready() function used in jquery?
Explain jquery connect?
How do I check if an element is hidden in jQuery?
What to do to select element having a particular class (".selected")? : jquery mobile
What is the use of jQuery.data() method?