Created
May 28, 2016 14:41
-
-
Save michaelvandenberg/0e1cbe4c95bf19ead1c016d2cda6a4f1 to your computer and use it in GitHub Desktop.
Remove empty <p> tags with jQuery.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Remove empty <p> tags. | |
* | |
* See: http://stackoverflow.com/questions/27781798/wordpress-retain-formatting-when-calling-extended-content#comment43990361_27782619 | |
* This seems to be the easiest solution. Remove this function if this ever gets fixed. | |
* Credits: http://stackoverflow.com/questions/6092855/how-do-i-remove-empty-p-tags-with-jquery | |
*/ | |
( function( $ ) { | |
$( 'p' ).each( function() { | |
var $this = $( this ); | |
if ( $this.html().replace( /\s| /g, '' ).length === 0 ) { | |
$this.remove(); | |
} | |
}); | |
})( jQuery ); |
consider this :
<h2>meet 1</h2><p>hi thre sdsd</p><p></p><p>sadjkasl</p>
now how can i remove
this ?????thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how can remove if nested tag also empty
example:
thanks