setEndBefore method (Range)
Sets the end position of the current Range to the start position of the specified node.
Note: The Range object and its setEndBefore method are supported in Internet Explorer from version 9.The end position of a Range is the first position in the DOM hierarchy that is after the Range. If you want the specified node to be the last element in the DOM hierarchy that is contained by the current Range, use the setEndAfter method. To set the end position to a point that is not the start or end point of any node, use the setEnd method.
- Similarly, the setStart, setStartBefore and setStartAfter methods set the start position of a Range.
- If you want to align the boundary points of a Range to the start and end points of an element or its contents, use the selectNode or selectNodeContents method.
- The boundary points of a Range object can be retrieved with the startContainer, startOffset, endContainer and endOffset properties.
You can find the related objects in the Supported by objects section below.
|Required. The end position of the current Range will be aligned to the start position of the element referenced by the node parameter.|
This method has no return value.
The setEndBefore (node) method is equivalent to the setEnd (parentNode, index) method, where the parentNode parameter refers to the parent node of the element specified by the node parameter and the value of the index parameter is the position of the element referenced by the node parameter in the childNodes collection of the element referenced by the parentNode parameter.
Example HTML code 1:
This example illustrates the use of the setEndBefore method:
Did you find this example helpful?
User Contributed Comments