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

What is resize() function in jquery?

654


How we can apply css in multiple selectors in jquery?

646


What is a jquery ajax?

566


How to fetch the values of selected checkbox array using jquery?

675


Explain cache paremeter of jquery ajax method?

596


Explain some of the key concepts of good code organization patterns.

646


Explain the common methods of sending a request to a server.

616


Which are the fastest selectors in jquery? : jquery mobile

563


How to set attributes of an element using jquery?

615


What is jquery.noconflict? Explain

621


What is the use jQuery.data method?

684


Explain remove class jquery with example?

590


What features of jquery, has been used in web applications?

595


Explain the difference between find and children methods in jquery?

614


What is the difference between jquery-x.x.x.js and jquery.x.x.x min.js?

617