how to hide attributes if detect this <p> </p>
My problem is when my client insert data(example table) with ckeditor , when i see the source code , ckeditor will add this <p> </p>
after table code. i know how to remove this manualy with source code(open source code and delete) but not my client!
how to hide attributes if detect this <p> </p>
My problem is when my client insert data(example table) with ckeditor , when i see the source code , ckeditor will add this <p> </p>
after table code. i know how to remove this manualy with source code(open source code and delete) but not my client!
- have you tried answer ? is it work for you ? – Pranay Rana Commented Apr 19, 2012 at 10:34
- WYSIWYG editors do this so that when someone clicks on the bottom of the text editor it gives them an actual place to put their cursor. Say if there's a table, the only other place to put the cursor would be inside of the table, and that's probably not what people want when using a WYSIWYG editor. – Kirkland Commented Aug 11, 2015 at 17:56
5 Answers
Reset to default 13Orignal answer : How do I remove empty p tags with jQuery?
Try
$('p').each(function() {
var $this = $(this);
if($this.html().replace(/\s| /g, '').length == 0)
$this.remove(); });
here is working code : http://jsfiddle.net/ambiguous/7L4WZ/
I think this should work. Pretty quick and hacky
$("p").each(function() {
var $el = $(this);
if($.trim($el.html()) == " ") {
$el.remove();
}
});
$('p').each(function(){
var value = $.trim($(this).html());
if(value == ' '){
$(this).remove();
}
});
this will work on all p tags so better to write selector with its parent tag, so it should not effect other page elements.
$('p').each(function() {
var $this = $(this);
if($this.html().replace(/\s| /g, '').length == 0)
$this.remove(); });
This worked like a charm for me. Thank you Pranay!
$('p').filter(function() {
return trim($(this).text()) == "";
}).remove();