I have textarea that I am using to add text and emojis when a user types. To get the smileys to work I have images that users can click or use the default on a users device keyboard. At the moment I can type in the box or use the emjois, I cant do both.
To get the unicode for the characters I have to add the unicode string to the textarea like:
var t = $('#msgWriteArea').html() + '&#x'+ code;
$('#msgWriteArea').html(t);
The problem I am having is when I type in the box before or after I insert these the text is accessible through the .val()
or value attribute and the Unicode characters are accessible through the .html()
or innerHtml
attribute.
Is there a way I can input text into a textarea as HTML instead of as a value or is there a way I can combine unicode characters and text in the same textarea.
JS Fiddle of the problem
Managed to fix the problem, there was quite a few things to change most importantly changing textarea to That made things a lot easier
Heres a fiddle,
Cant take all the credit, the answers for these questions helped
Insert text into textarea with jQuery
Get caret position in contentEditable div
How to set caret(cursor) position in contenteditable element (div)?
How to replace selected text with html in a contenteditable element?
Its not the neatest coding and probably could be done better, feel free to edit the fiddle make it better if you can it may help others who are stuck in the same place