The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
selectionStart property
Gets or sets the starting position or offset of a text selection.
![]() ![]() |
Syntax
| JavaScript | |
|---|
Property values
Type: Integer
The starting position of the text selection.
Standards information
- HTML5 A vocabulary and associated APIs for HTML and XHTML, Section 7.6.2
Examples
The following code example shows how to set a text selection's start and end positions.
<!DOCTYPE html>
<html>
<head>
<title>Selection Start and End example</title>
<script type="text/javascript">
function SelectSomeText () {
var input = document.getElementById ("Textbox");
input.selectionStart = 4;
input.selectionEnd = 13;
}
</script>
</head>
<body>
<p><input type="text" id="Textbox" size="40" value="The text selection appears here"/></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
Show:

