I'm using a div with contenteditable as a textarea, so I can insert PNG emoji. Now everything works fine except for when I want to insert the emoji in the current caret position. I only know .append() which simply inserts the emoji at the end of the text. this is my code:
<div id="message-field" class="form-control message-field" contenteditable="true"></div>
<span class="em em-1F3C6" data-em="1F3C6"></span>
<span class="em em-1F6AB" data-em="1F6AB"></span>
<span class="em em-1F44D" data-em="1F44D"></span>
<span class="em em-1F44E" data-em="1F44E"></span>
$('.em').click(function() {
var em = $(this).data('em');
$('#message-field').append('<img src="_/css/img/emoji/' + em + '.png"> ');
});
Now how to make it insert the emoji in the current caret position and not in the end?
Thanks!