Programming
XML DOM compareBoundaryPoints() Method
Definition and Usage
The compareBoundaryPoints() method compares the positions of two ranges.
Syntax:howcompareBoundaryPoints(sourceRange,
)
) | description |
---|---|
how | Parameter |
sourceRange | To compare the range to be compared with the current range. It declares how the comparison operation is to be performed (i.e., which boundary points are to be compared). Its valid values are constants defined by the Range interface. |
Return value
If the specified boundary point of the current range is located sourceRange before the specified boundary point, then return -1. If the two specified boundary points are the same, then return 0. If the boundary points of the current range are located sourceRange after the specified boundary point, then return 1.
throw
If sourceRange indicates that the document represented by the method is different from the document represented by the current range, and the method will throw an error code of WRONG_DOCUMENT_ERR. DOMException exception.
description
This method compares the boundary points of the current range and the specified sourceRange boundary points and returns a value that declares their relative position in the source document. The parameter how specifies which boundary point of two ranges to compare. The valid values of this parameter and their meanings are as follows:
- Range.START_TO_START - Compare the start points of two Range nodes
- Range.END_TO_END - Compare the end points of two Range nodes
- Range.START_TO_END - Using sourceRange the start point is compared with the end point of the current range
- Range.END_TO_START - Using sourceRange the end point is compared with the start point of the current range
The return value of this method is a number that declares the relative position of the current range to sourceRange location. Therefore, you may think that you need to use the parameter how The range constants specify the boundary points of the current range and then use it to specify sourceRange boundary points. However, the constant Range.START_TO_END specifies the boundary points of the current range and sourceRange to compare with the start point. Similarly, the constant Range.END_TO_START specifies comparing the start point of the current range with the end point of the specified range.