Target Empty Paragraph Tags and Remove

When adding content, sometimes it’s necessary to add in extra non-breaking spaces to adjust spacing on desktop. Even some plugins (Shortcodes Ultimate) will create additional paragraph tags in the content area that cannot be removed from the editor.

The below snippet allows you to target non-breaking spaces, and empty paragraph tags to remove them.

This comes in handy especially on handheld devices when the layout collapses, and the larger gaps are more noticeable.

jQuery("p").filter( function() {

var html = jQuery(this).html();

if(html == '' || html == ' ')
return true;

}).addClass('emptyP');

Source.

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.