Position insert bar in editable jquery div

1

I'm using the summernote API as the editor for email, it creates a div to be used as textarea. The only reference that leaves is the "note-editable" class. I made a code to replace a word with a tag with content-editable false so that the user tries to delete it, erase all the text from it. or the code I use:

function insertTag(string, tag){
    string[0] = string[0]  + '<span contentEditable="false" class="enfatizar">' + tag + '</span>&nbsp;';
    var position = string[0].lenght;
    code = string[0] + string[1];
    $('#inputMsgEmail').code(code);
}

I wanted to insert the insertion bar into the div '.note-editable' by means of the returned lenght, something like:

$('.note-editable').caretPosition(position);
    
asked by anonymous 03.02.2015 / 18:41

1 answer

1

You're using this summernote , right? If so, come on.

The API provides a callback of onChange , which, one of the parameters sent is 'content', I think it would be worth using such a callback to check the content and then add the classes and treats.

As for your doubt, I did not quite understand, could it be any clearer? :)

But seeing your code, I noticed that you are not using the position variable anywhere in your function, and because it is local the same ends up being unusable throughout your file.

    
04.02.2015 / 02:11