Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Last active August 29, 2015 13:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/51f84be9c72e86b67480 to your computer and use it in GitHub Desktop.
Save tommcfarlin/51f84be9c72e86b67480 to your computer and use it in GitHub Desktop.
[JavaScript] How to remove empty `code` elements using jQuery.
<p>
<code>This is my original multiline
comment that includes carriage returns</code>
<code>
</code>
<code>
and new lines throughout the comments.
</code>
</p>
<code>This is my original multiline
comment that includes carriage returns
and new lines throughout the comments.
</code>
( function ( $) {
'use strict';
$( '.comment code' ).each(function() {
if ( '' === $.trim( $( this ).text() ) ) {
$( this ).remove();
}
});
}( jQuery ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment