Saturday, 24 August 2013

Previous Interview Question Next Interview Question
Home

How do you check if an element is empty?

There are 2 ways to check if element is empty or not. We can check using ":empty" selector.
$(document).ready(function(){
    if ($('#element').is(':empty')){
       //Element is empty
  }
});
And the second way is using the "$.trim()" method.
$(document).ready(function(){
     if($.trim($('#element').html())=='') {
       //Element is empty
  }
});

Previous Interview Question Next Interview Question
Home

0 comments :

Post a Comment