You are here: Reference > JavaScript > client-side > selection and ranges > methods > moveStart (TextRange)

moveStart method (TextRange)

Browser support:
10.5
Moves the start position of the current TextRange object by the specified number of units.
Use the moveEnd method to move the end position.

Syntax:

object.moveStart (unitToMove [, numberOfUnits]);
You can find the related objects in the Supported by objects section below.

Parameters:

unitToMove
Required. String that specifies the type of unit to move by.
One of the following values:
character
Moves the start position by characters.
sentence
Moves the start position by sentences.
textedit
Moves the start position to the end of the editable region.
word
Moves the start position by words. Word characters mean alphanumeric characters.
numberOfUnits
Optional. Integer that specifies the number of units to move by. Default is 1. Negative and positive values are also allowed.

Return value:

Integer. Returns the number of units moved.

Example HTML code 1:

This example illustrates the use of the moveStart method:
<head>
    <script type="text/javascript">
        function ExtendSelection () {
            if (document.selection) {        // Internet Explorer
                var myRange = document.selection.createRange ();
                myRange.moveStart ("character", -1);                                        
                myRange.select ();
            }
            else {
                alert ("Your browser does not support this example!");
            }
        }
    </script>
</head>
<body>
    <div contenteditable="true">Some text for selection.</div>
    <br /><br />
    <button onclick="ExtendSelection ()">Extend the selection by one character at the beginning!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content