get the app get the app       get the app       get the app
How do you check if an element is empty?


  • : 302
  • : 15
    Previous Next

    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
    }
    });

    you can suggest other answer in comment box


  • Exam: jQuery Interview





    Recommended Learning for you

    Close(X)
    Subscribe here for free mock test on IAS PCS SSC and other competitive exam. Signup here to get SSC CGL Solution and main exam study material