Hendry H.
Hendry H.

Reputation: 1520

tinymce 4 how to put cursor to end of the text

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 ?

Upvotes: 18

Views: 20359

Answers (1)

Hendry H.
Hendry H.

Reputation: 1520

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);

Upvotes: 45

Related Questions