Using an if statement to check if a div is empty

前端 未结 10 1144
忘了有多久
忘了有多久 2020-11-28 03:20

I\'m trying to remove a specific div if a separate div is empty. Here\'s what I\'m using:

$(document).ready(function () {
    if (\'#leftmenu:empty\') {
             


        
10条回答
  •  余生分开走
    2020-11-28 03:21

    You can extend jQuery functionality like this :

    Extend :

    (function($){
        jQuery.fn.checkEmpty = function() {
           return !$.trim(this.html()).length;
        };
    }(jQuery));
    

    Use :

    if($("#selector").checkEmpty()){ console.log("Empty"); }else{ console.log("Not Empty"); }

提交回复
热议问题