A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/dom/HTMLInputElement/setSelectionRange below:

setSelectionRange · WebPlatform Docs

setSelectionRange

Method of dom/HTMLInputElementdom/HTMLInputElement

Syntax
var object = object.setSelectionRange(start, end);
Parameters start
Data-type
any

The offset into the text field for the start of the selection.

end
Data-type
any

The offset into the text field for the end of the selection.

Return Value

Returns an object of type DOM NodeDOM Node

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Examples

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

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=9" /> 
<title>Example of setSelectionRange()</title>
    <script>
        function SelectSomeText () {
            var input = document.getElementById ("Textbox");
                input.setSelectionRange (4,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>
Notes Remarks

If you set a parameter to more than the length of the text field, the parameter points to the end of the text field. If the end parameter is less than or equal to the start paramenter, the start and end positions of the selection are set to the end value. The selection is then an insertion point or caret.

Syntax Standards information See also Related pages Attributions

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4