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 |
Tell me what is the use of .size() method in jquery?
What is the difference between jquery and javascript?
How does jquery mobile theming work? : jquery mobile
What are the approaches of extracting a query string with regular expressions?
How to validate email using jquery?
What is the use of clone method in jQuery?
Is jQuery a programming language?
Back onto jquery ui' can you see jquery ui making more of an impression in the future, lead by the current successes of jquery?
How do you select all elements with the class of “selected” in jquery?
How do you attach a event to element which should be executed only once?
How to redirect to another page using jquery?
What are the difference between alert() and confirm()?