I am trying to create a selection that goes from right to left in the text, but it seems that the DOM Range API does not allow me to do this. (I donβt see anything about this in the specification, and not that I read it carefully, but all implementations seem to agree not to support it.)
For example, given a very minimal document:
data:text/html,<div> this is a test </div>
I can use this script to enable editing and create a normal selection (for example, from a bookmarklet, but adding a line is added for clarity):
javascript:document.designMode='on';
var r=document.createRange(),d=document.getElementsByTagName('div')[0];
r.setStart(d.firstChild, 3);
r.setEnd(d.firstChild, 7);
window.getSelection().addRange(r); void(0);
However, if I change 3 and 7, the selection will not be created.
Does anyone know how to do this?
source
share