compareBoundaryPoints
Summary
The Range.compareBoundaryPoints() method compares the boundary points of the Range with another one.
Syntax
var boundaryComparison = range.compareBoundaryPoints(/* see parameter list */);
Parameters
how
- Data-type
- unsigned short
Specifies how sourceRange is compared to the range of the object on which compareBoundaryPoints is invoked.
Must be one of -
`Range.END_TO_END` (2) compares the end boundary-point of sourceRange to the end boundary-point of Range.
`Range.END_TO_START` (3) compares the end boundary-point of sourceRange to the start boundary-point of Range.
`Range.START_TO_END` (1) compares the start boundary-point of sourceRange to the end boundary-point of Range.
`Range.START_TO_START` (0) compares the start boundary-point of sourceRange to the start boundary-point of Range.
sourceRange
- Data-type
- Range
Range object that is compared to the range of the object on which compareBoundaryPoints is invoked.
Return Value
Returns an object of type NumberNumber
Returns a –1, 0, or 1 to indicate whether the sourceRange point is before, equal to, or after the boundary point of the Range object on which compareBoundaryPoints is invoked.
Examples
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);
Related specifications
- DOM
- Living Standard
- DOM Level 2 Traversal and Range
- Recommendation
Attributions
Mozilla Developer Network : [Range.compareBoundaryPoints Article]
Microsoft Developer Network: [compareBoundaryPoints Method Article]