Ramesh
Ramesh

Reputation: 1083

How to expand/enlarge Text selection in CKEditor using javascript.?

Can anyone tell me how to expand or enlarge the selection in CKEditor.

I can get the selection using

var EditorInstance = CKEDITOR.instances['Editor'];
var selection = EditorInstance.getSelection();

but what i want is to enlarge that selection with javascript.

For example this is my selection now

enter image description here

then i want to expand or enlarge that selection like this

enter image description here

And this selection may contain tags like bold italic also.. Using javaScript only please help me..

Upvotes: 1

Views: 723

Answers (1)

Jake Stoeffler
Jake Stoeffler

Reputation: 2875

To extend the Selection you can use the modify() method as long as you're in a modern web browser. For example, to extend the selection forward by one word, you could do this:

var selection = window.getSelection();
selection.modify("extend", "forward", "word");

You can also specify to extend backward, and you can specify to extend by word, character, line, etc.

Upvotes: 1

Related Questions