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

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

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

+3
source share
4 answers

Orignal answer: How to remove empty p tags using jQuery?

Try

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

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

+8
source

I think this should work. Pretty fast and hacky

$("p").each(function() { 
   var $el = $(this);
   if($.trim($el.html()) == "&nbsp;") {
     $el.remove();
   }
 });
+1
source
$('p').each(function(){
    var value = $.trim($(this).html());
    if(value == '&nbsp;'){
        $(this).remove();
    }
});

p-, , .

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

. , !

0

All Articles