You are here: Reference > JavaScript > client-side > event handling > properties > rangeParent (event)

rangeParent property (event)

Browser support:
Returns a reference to the element where the selection ends.
The rangeParent and rangeOffset properties together specify the end position of the selection. The use of them is not recommended.
A more useful solution is to create a selectionRange object from the current selection with the getSelection method. The selectionRange object is widely supported and provides various information about the current selection.
For example the focusNode and focusOffset properties together specify the end position of the selection. The example below illustrates it.

Syntax:

object.rangeParent;
You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

Reference to the element where the selection ends.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the focusNode property instead of the rangeOffset property:
<head>
    <script type="text/javascript">
        function GetOrigTarget (event) {
            if (event.rangeParent) {
                alert ("The contents of the element where the selection ends:\n" + event.rangeParent.textContent);
                alert ("The end position of the selection: " + event.rangeOffset);
            }

            if (window.getSelection) {
                var selRange = window.getSelection ();
                alert ("The contents of the element where the selection ends:\n" + selRange.focusNode.textContent);
                alert ("The end position of the selection: " + selRange.focusOffset);
            }

        }
    </script>
</head>
<body>
    <div onmouseup="GetOrigTarget (event);">Select a part of this text!</div>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

User Contributed Comments

Post Content

Post Content