My Blog: The Empty Paragraph Problem

17 January 2017

They really really annoy me. They are empty paragraphs... used by some novice website editors to insert extra spaces between one block of text and the next. This is how I get rid of them.

Just a quick blog entry to highlight how I remove empty paragraphs from my website after other editors insist on adding them. A simple bit of JavaScript JQuery code:

$(document).ready(function () {
    // Remove empty paragraphs from pages:
    $('p').each(function () {
        var $this = $(this);
        if ($this.html().replace(/\s| /g, '').length == 0)

It's a short-term fix until I find and remove them from the HTML code, but at least my website visitors don't have to suffer large blocks of white-space between blocks of text.

I could also apply this function to headings <h1> through <h6>, as well as list items <li>.

comments powered by Disqus