tinymce 4 how to put cursor to end of the text

Hendry H. picture Hendry H. · Nov 7, 2013 · Viewed 13.7k times · Source

For some reason, I need to execute :

tinyMCE.activeEditor.setContent(text, {format : 'html'});

After that, how to put the cursor to the end of the text ?

Answer

Hendry H. picture Hendry H. · Nov 7, 2013
ed.selection.select(ed.getBody(), true); // ed is the editor instance
ed.selection.collapse(false);

This seems to be answered by Peter Wooster in thread jQuery Set Cursor Position in Text Area

EDIT For TINYMCE use:

tinyMCE.activeEditor.selection.select(tinyMCE.activeEditor.getBody(), true);
tinyMCE.activeEditor.selection.collapse(false);