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".
Syntax
| JavaScript | |
|---|
Property values
Type: DOMString
The direction of the text selection.
Standards information
- HTML 5.1, Section 4.10.20
Remarks
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".
Examples
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>
<html>
<head>
<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");
output.value=input.selectionDirection;
}
</script>
</head>
<body>
<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>
</body>
</html>
See also
- HTMLInputElement
- input type=email
- input type=number
- input type=range
- input type=search
- input type=tel
- input type=text
- input type=url
- textArea