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

move method (TextRange)

Browser support:
Moves the end point of the current TextRange object to its start point and moves the collapsed TextRange object by the specified number of units.
If you need to move only the start or end point of a TextRange, use the moveStart and moveEnd methods.


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


Required. String that specifies the type of unit to move by.
One of the following values:
Moves the collapsed TextRange object by characters.
Moves the collapsed TextRange object by sentences.
Moves the collapsed TextRange to the end of the document's content.
Moves the collapsed TextRange object by words. Word characters mean alphanumeric characters.
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 move method:
    <script type="text/javascript">
        function CaretToNextChar () {
            if (document.selection) {        // Internet Explorer
                var myRange = document.selection.createRange ();
                myRange.move ("character");                                        
    <div contenteditable="true">Some text for selection.</div>
    <br /><br />
    <button onclick="CaretToNextChar ()">Place the caret after the first selected character!</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content