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...
$("<p> </p>").remove();
Although the code above does nothing.
* Removes empty paragraph tags from shortcodes in WordPress. add_filter( 'the_content' , 'tg_remove_empty_paragraph_tags_from_shortcodes_wordpress' ); That's it! All empty paragraph tags have been removed from your shortcodes.
The empty() method removes all child nodes and content from the selected elements. Note: This method does not remove the element itself, or its attributes. Tip: To remove the elements without removing data and events, use the detach() method. Tip: To remove the elements and its data and events, use the remove() method.
empty() will empty the selection of its contents, but preserve the selection itself. remove() will empty the selection of its contents and remove the selection itself.
Method 1: Using the “:empty” selector: The element to be checked using is() method. The is() method is used to check if one of the selected elements matches to the selector element. This method can be used on this element to test if it is empty by using “:empty” selector.
The answer depends on what "empty" means. If the empty paragraphs are <p></p>
then fireeyedboy's p:empty
selector is the way to go. If there could be spaces or newlines or other such things then you'll probably want something like this:
$('p').each(function() { const $this = $(this); if($this.html().replace(/\s| /g, '').length === 0) $this.remove(); });
Example: http://jsfiddle.net/ambiguous/7L4WZ/
FCKEditor (not sure about CKEditor or TinyMCE) likes to add <p> </p>
to the HTML so you might need the above somewhat ugly approach.
Try:
$( 'p:empty' ).remove();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With