Search code examples
tinymcetinymce-3

TinyMCE: Move cursor to end of inserted text


I have insert a line break within TinyMCE

tinyMCE.execCommand('mceInsertContent',false, "<br/>");

However the cursor currently stays where it was before.. which makes sense, however I would like code which moves the cursor the end of the html I just inserted?


Solution

  • Adding a space after the <br/> will reposition the cursor:

    So change:

    tinyMCE.execCommand('mceInsertContent',false, "<br/>");
    

    to

    tinyMCE.execCommand('mceInsertContent',false, "<br/> ");
    

    Example: http://codepen.io/anon/pen/PbKQpJ (demo links above editor)