How do you check if an element is empty?



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

Post New Answer

More jQuery Interview Questions

What is the difference between eq() and get() methods in jQuery?

1 Answers  


Define type paremeter of jquery ajax method?

1 Answers  


What is the difference between parent() and parents() methods in jQuery?

1 Answers  


explain bind() vs live() vs delegate() methods in jquery

1 Answers  


What is the difference between $('div') and $('<div/>') in jQuery?

1 Answers  


In jquery, what is the meaning of toggle?

1 Answers  


Tell me how to disable jquery animation? : jquery mobile

1 Answers  


Define slidetoggle() effect?

1 Answers  


How to include jQuery in ASP.Net project?

1 Answers  


How can you add a jquery library in your project?

1 Answers  


Is jquery a library for client scripting or server scripting? : jquery mobile

1 Answers  


What is the difference between size and length of jQuery?

1 Answers  


Categories