I use twemoji to display emoji in an input field (contaseditable div):
<div contenteditable="true" id="input_div"></div>
the user can add emoji using an external button so that I can just add it to the div (let it not care about the caret position):
div.innerHTML += twemoji.parse(emoji);
next I need to get user input from a div with emoji, is there an easy way to convert back to Unicode characters?
my current solution is here (I just parse <img> to get the alt attribute), but I think it looks a little more complicated, and I canβt use the div.innerText property (itβs convenient enough to get plain text from the div), because Iβll lose emojis. I also use div.getInnerText to prevent pasting html or clipboard images:
div.addEventListener("insert", () => {setTimeout(div.innerText = div.innerText,0)})
source share