I'm trying to build a selection tool in js, for diverse reasons. To maintain a variety of selections, it's based on the index/ offset in the string. Except that if there is an encoded html character in it, it's considered as one character, and not 4.
Example : https://jsfiddle.net/1nLszqoa/
<div id="banner-message">
<p><Hello World</p>
</div>
document.addEventListener('mouseup', function() {
var selection = document.getSelection();
console.log(selection);
});
If you select "<H", the focusOffset (in console) will be 2. Except that Html wise, it's 5.
Do you know any simple workaround? I know that I could maybe use a textarea instead, but for now I'm pursuing this lead.
Thank you