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 mean ?
How do you add an HTML element in DOM tree?
Difference between javascript and jquery? : jQuery Mobile
Explain the each() function?
Is it possible that jquery html work for both html and xml document?
Consider a scenario where things can be done easily with javascript, would you still prefer jQuery?
Explain event.preventdefault? : jquery mobile
Define data paremeter of jquery ajax method?
How can events be prevented from stopping to work after an ajax request?
What is the difference between onload() and document.ready()?
What is jquery toggle function?
How to execute jQuery code after the DOM is ready?