How do I remove empty p tags with jQuery?

后端 未结 6 880
后悔当初
后悔当初 2020-12-04 22:32

The platform I\'m building a website on produces empty p tags in wysiwyg mode. How can I take these out?

Something like this, perhaps...

$

6条回答
  •  一生所求
    2020-12-04 23:12

    Thanks "mu is too short",

    I've tried your code It works but I need to wrap it in jQuery(document).ready(function() {});

    The full code worked for me is:

    jQuery(document).ready(function() {
        jQuery('p').each(function() {
            var $this = jQuery(this);
            if($this.html().replace(/\s| /g, '').length == 0) {
                $this.remove();
            }
        });
    });
    

    I don't know why this happens, My jQuery/JS is not so good, I'm learning it ;).

    Hope this help another person like me.

    Thanks.

提交回复
热议问题