How do you check if an element is empty?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to disable cut,copy and paste in TextBox using jQuery?

485


How to resolve conflicts with other libraries?

509


What is the use of css() method in jquery?

482


Explain the difference between .js and .min.js?

486


How can we give face effect in jquery?

486






In what scenarios jQuery can be used?

507


How to call a method inside code-behind using jquery?

477


How to get the style property of an element using ?

420


Is vanilla js faster than jquery?

461


Can you write a code to select all links inside the paragraph?

518


How to disable/enable an element in jquery?

501


What is the need for jquery? : jQuery Mobile

498


Is jquery a w3c standard? : jquery mobile

524


Explain type paremeter of jquery ajax method?

448


Tell me which command will give a version of jquery?

413