As of r92088 and
WebKit and Mozilla respectively support
property on input and textarea HTML elements.
selectionDirection property lets web sites figure out which side of the selection is anchor and focus.
anchor and focus were obtained through
However, these functions don’t work with selections inside input and textarea
like other methods and properties of
input and textarea elements instead provide properties such as
selectionEnd to let websites control selection within them.
So we’ve added
selectionDirection, which is a property on
that takes the following values:
none- selection is directionless; neither start nor end is identified as anchor nor focus.
forward- selection start is anchor and selection end is focus.
backward- selection end is anchor and selection start is focus.
setSelectionRange now takes the direction as the 3rd argument so the following code will select “hello world”:
<input type="text" value="hello world WebKit"> <script> var text = document.getElementsByTagName('input'); text.focus(); text.setSelectionRange(6, 11, 'backward'); window.getSelection().modify('extend', 'left', 'word'); alert(text.selectionDirection); // This will show 'backward'; </script>
You can learn more about selectionDirection property on HTML5 spec.