Export (0) Print
Expand All
all
alt
ch
dir
id
min
rel
top
url
URL
urn
Expand Minimize
This topic has not yet been rated - Rate this topic

selectionEnd property

Gets or sets the end position or offset of a text selection.

HTML5 A vocabulary and associated APIs for HTML and XHTML, Section 7.6.2Internet Explorer 9

Syntax

JavaScript

p = object.selectionEnd

Property values

Type: Integer

The end position of the text selection.

Standards information

Remarks

If you do not select text, selectionEnd returns the offset of the character that immediately follows the text cursor or caret.

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

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.