Position insert bar in jquery editable div

Asked

Viewed 211 times

1

I’m using the summernote API as an email editor, it creates a div to be used as a textarea. The only reference it 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, delete all text from it. 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);
}

Wanted through the returned lenght to insert the insert bar in div '.note-Editable', something like:

$('.note-editable').caretPosition(position);
  • That function code is from the plugin (summernote)?

1 answer

1

You are using this summernote, right? If so, let’s go.

The API offers a callback of onChange, that, one of the parameters sent is 'content', I think it would be valid to use such callback to check the content and then add the classes and treats.

As for your doubt, I don’t quite understand it, it could be clearer? :)

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

  • Yeah, that’s the one. Well, I have to insert a tag similar to facebook, twitter, which replaces itself with an unedited element and highlighted, the user type @student, arise the tag <span> contentEditable="false" class="emphasize">@ STUDENT</span>, for when trying to delete a character deleting the whole sentence, what I need is repositioning the insertion bar after changing the word @studentto tag, the position variable would be for repositioning the insertion bar after the replaced word, or if possible, capture the position by a method and then restore...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.