How to remove elements with whitespace?

前端 未结 5 914
暖寄归人
暖寄归人 2020-12-17 01:09

I can easily remove a tag that has no blank spaces...

$(\'h2:empty\').remove();

But, when there is a space...

&l

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-17 01:14

    try this

    $("h2").each(function(){
       var self = $(this);
       if ( self.html().trim().length == 0 )
       {
         self.remove();
       }
    });
    

提交回复
热议问题