Collapse the table of content
Expand the table of content

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



HRESULT value = object.put_selectionEnd( v);HRESULT value = object.get_selectionEnd(* p);

Property values

Type: long

The end position of the text selection.

Standards information


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


The following code example shows how to set a text selection's start and end positions.

<!DOCTYPE html>
<title>Selection Start and End example</title>
    <script type="text/javascript">
        function SelectSomeText () {
            var input = document.getElementById ("Textbox");
                input.selectionStart = 4;
                input.selectionEnd = 13;                
    <p><input type="text" id="Textbox" size="40" value="The text selection appears here"/></p>
    <p><button onclick="SelectSomeText ()">See selection</button></p>



Community Additions

© 2015 Microsoft