JSFiddle - React, Tailwind, and code Playground
HTML
Hello World<br /> <br />
Hello World<br /> <br />
Hello World<br /> <br />
JavaScript
// it's better to wait for document ready instead of window.onload
window.onload = function () {
// get all `br` tags, defined needed variables
var br = document.getElementsByTagName('br'),
l = br.length,
i = 0,
nextelem, elemname, include;
// loop through tags
for (i; i < l - 1; i++) {
// this flag indentify we should hide the next element or not
include = false;
// getting next element
nextelem = br[i].nextSibling;
// getting element name
elemname = nextelem.nodeName.toLowerCase();
// if element name is `br`, set the flag as true
if (elemname == 'br') {
include = true;
}
// if element name is `#text`, we face text node
else if (elemname == '#text') {
// if text node is only white space, we must pass it
// this is because of something like this: `<br /> <br />`
if (! nextelem.data.replace(/\s+/g, '').length) {
nextelem = br[i+1];
include = true;
}
}
// if the element is flagged as true, hide it
if (include) {
nextelem.style.display = 'none';
}
}
};