Search code examples
javascriptjqueryckeditor

remove <p> &nbsp;</p> with jquery if no value


how to hide attributes if detect this <p> &nbsp;</p>

My problem is when my client insert data(example table) with ckeditor , when i see the source code , ckeditor will add this <p> &nbsp;</p> after table code. i know how to remove this manualy with source code(open source code and delete) but not my client!


Solution

  • Orignal answer : How do I remove empty p tags with jQuery?

    Try

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

    here is working code : http://jsfiddle.net/ambiguous/7L4WZ/