I create a Range object and then add this Range to selection
window.getSelection ().addRange(myRange);
How to set the selection direction?
I mean direction which can be checked using the anchorNode, anchorOffset, focusNode and focusOffset properties of selections.
You can do this on browsers that support the
extend()(MDN) method ofSelectionobjects. Mozilla, WebKit and Opera support it; IE does not up to and including version 11.extend()has been added to the HTML Editing APIs spec so it may yet appear in IE.Here’s an example function: