I have an editable div and there it should replace emoticon-keys while typing.
There is an hidden textarea also and there should be the raw data, but i dont't get how this should work.
I use this library.
My jquery code:
$('#acompose_message').keyup(function() {
val = $('#acompose_message').html();
document.getElementById('compose_message').innerHTML = val;
emotifyVal = emotify(val);
$('#acompose_message').html(emotifyVal);
});
'#acompose_message' is the editable div and '#compose_message' is the hidden div
Now I almost solved my problem :
var emotifyText = function(e) {
var caretPosition = getCaretPosition(this);
var images = [];
var i = 0;
val = $('#acompose_message').html();
var emotifyVal = emotify(val);
$('#acompose_message').html(emotifyVal);
$.each($('#acompose_message img'), function(index){
console.log(i);
$(this).replaceWith(function(){
return jQuery.inArray( $(this).attr('src'), jsonIcons );
});
i++;
});
val = $('#acompose_message').html();
var emotifyVal = emotify(val);
$('#compose_message').val(val);
$('#acompose_message').html(emotify(val));
};
but the line with $(this).replaceWith(function(){
does not work, now my Question is, does somebody knows how i can replace every img in my div with an other string?