Another solution, if you do not need to be semantic (because you will get a lot of spans), I mean, if you only need a visual result, use flexbox.
So you have <div id="#myText">TEXT 1</div>
We need to get the following:
<div id="#myText"> <span>T</span> <span>E</span> <span>X</span> <span>T</span> <span> </span> <span>1</span> </div>
So you can apply CSS:
#myText { display: flex; flex-direction: row; justify-content: space-between; }
To convert text to a range, you can use jQuery or something else. Here with jQuery:
var words = $('#myText').text().split(""); $('#myText').empty(); $.each(words, function(i, v) { if(v===' '){ $('#myText').append('<span> </span>'); } else { $('#myText').append($("<span>").text(v)); } });
For best results, remove put-spacing: 0 in #myText so that the extra spacing is applied.
perseus
source share