Skip to main content
selectionDirection property

Gets the string corresponding to the current selection's direction. Depending on which direction the selection is being made, possible values are "forward" for a forward selection, "backward" for a backward selection, and "none".



p = object.selectionDirection


Property values

Type: DOMString

The direction of the text selection.

Standards information


Gets the current direction of the selection.

The selectionDirection attribute can be set to change the direction of the selection. The possible values are "forward", "backward", and "none".


The following code example shows a textbox that has its text selected backwards using setSelectionRange. The selectionDirection attribute is used to get the direction of this selection ("backwards"), which is then set to the value of the second textbox.

<!DOCTYPE html>
<title>Example of selectionDirection</title>
    <script type="text/javascript">
        function SelectSomeText () {
            var input = document.getElementById ("Textbox-in");
            var output = document.getElementById ("Textbox-out");
            input.setSelectionRange (4,13,"backward");
    <p>Selection: <input type="text" id="Textbox-in" size="40" value="The text selection appears here"/></p>
    <p>Direction: <input type="text" id="Textbox-out" size="40" /></p>
    <p><button onclick="SelectSomeText ()">See selection</button></p>

See also

input type=email
input type=number
input type=range
input type=search
input type=tel
input type=text
input type=url