JSFiddle - React, Tailwind, and code Playground
by kuonyuu
HTML
<p>No Space</p>
<p> 1 Space</p>
<p> 2 Spaces</p>
<p> 3 Spaces</p>
<p> 4 Spaces</p>
JavaScript
/* $(document).ready(function() {
$('p').each(function(){
$(this).html($(this).html().replace(/ /gi,''));
});
}); */
var els = document.getElementsByTagName("P");
for(var i = 0, l = els.length; i < l; i++) {
var txt = els[i].innerHTML;
txt.replace(/ /gi,'');
txt = txt.trim();
txt = txt.split(' ').join('');
//if (txt != "" ) txt = " " + txt;
}