You are here: Reference > JavaScript > client-side > event handling > properties > rangeOffset (event)
rangeOffset property (event)
Returns the end position of the current selection relative to the element referred to by the rangeParent.
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:
You can find the related objects in the Supported by objects section below.
This property is read-only.
Possible values:
Integer that retrieves the end position.
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the focusOffset 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?
|
Supported by objects:
Related pages:
User Contributed Comments