The Range.compareBoundaryPoints() method compares the boundary points of the Range with those of another range.
Syntax
compare = range.compareBoundaryPoints(how, sourceRange);
Return value
compare- A number,
-1,0, or1, indicating whether the corresponding boundary-point of theRangeis respectively before, equal to, or after the corresponding boundary-point of sourceRange.
Parameters
how- A constant describing the comparison method:
Range.END_TO_ENDcompares the end boundary-point of sourceRange to the end boundary-point ofRange.Range.END_TO_STARTcompares the end boundary-point of sourceRange to the start boundary-point ofRange.Range.START_TO_ENDcompares the start boundary-point of sourceRange to the end boundary-point ofRange.Range.START_TO_STARTcompares the start boundary-point of sourceRange to the start boundary-point ofRange.
If the value of the parameter is invalid, a
DOMExceptionwith aNotSupportedErrorcode is thrown. sourceRange- A
Rangeto compare boundary points with the range.
Example
var range, sourceRange, compare;
range = document.createRange();
range.selectNode(document.getElementsByTagName("div")[0]);
sourceRange = document.createRange();
sourceRange.selectNode(document.getElementsByTagName("div")[1]);
compare = range.compareBoundaryPoints(Range.START_TO_END, sourceRange);
Specifications
| Specification | Status | Comment |
|---|---|---|
| DOM The definition of 'Range.compareBoundaryPoints()' in that specification. |
Living Standard | No change. |
| Document Object Model (DOM) Level 2 Traversal and Range Specification The definition of 'Range.compareBoundaryPoints()' in that specification. |
Obsolete | Initial specification. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
compareBoundaryPoints | Chrome Full support Yes | Edge Full support 12 | Firefox Full support 4 | IE Full support 9 | Opera Full support 9 | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
Legend
- Full support
- Full support
