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

moveToPoint method (TextRange)

Browser support:
Moves the start and end points of the current TextRange object to the specified position.

Syntax:

object.moveToPoint (X, Y);
You can find the related objects in the Supported by objects section below.

Parameters:

X
Required. Integer that specifies the horizontal coordinate of the point in pixels relative to the top-left corner of the browser window's client area.
Y
Required. Integer that specifies the vertical coordinate of the point in pixels relative to the top-left corner of the browser window's client area.

Return value:

This method has no return value.

Example HTML code 1:

This example illustrates the use of the moveToPoint method:
<head>
    <script type="text/javascript">
        function FollowMouse () {
            if (document.body.createTextRange) {        // Internet Explorer
                var range = document.body.createTextRange ();
                range.moveToPoint (event.clientX, event.clientY);
                range.select ();
            }
        }
    </script>
</head>
<body>
    <div contenteditable="true" onmousemove="FollowMouse ()">
        Move your mouse over this text, the caret will follow it.
    </div>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content