Visit Mozilla.org

DOM:range.compareBoundaryPoints

From MDC

« Gecko DOM Reference

Contents

[edit] Summary

Compares the boundary points of two Ranges.

[edit] Syntax

compare = range.compareBoundaryPoints(how, sourceRange);
compare 
A number, -1, 0, or 1, indicating whether the corresponding boundary-point of range is respectively before, equal to, or after the corresponding boundary-point of sourceRange.
how 
A constant describing the comparison method, one of values described below.
sourceRange 
A Range to compare boundary points with range

[edit] 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);

[edit] Notes

Any of the following constants can be passed as the value of how parameter:

  • Range.END_TO_END compares the end boundary-point of sourceRange to the end boundary-point of range.
  • Range.END_TO_START compares the end boundary-point of sourceRange to the start boundary-point of range.
  • Range.START_TO_END compares the start boundary-point of sourceRange to the end boundary-point of range.
  • Range.START_TO_START compares the start boundary-point of sourceRange to the start boundary-point of range.

[edit] Specification

DOM Level 2 Traversal: compareBoundaryPoints