Javascript Reference
Categories: Range

javascript Range compareBoundaryPoints( )

@March 15, 2008, 1:22 a.m.
compareBoundaryPoints( )Firefox/Netscape/NN 6 IE n/a Chrome/Safari/DOM 2  

compareBoundaryPoints(compareType, sourceRangeRef)

  

Returns an integer code indicating the relative positioning of one boundary point of the current range's against a boundary point of a different text range. In the simplest case, the two end points (one from each range) share the same ancestor container. In such a case, the first parameter determines which end points from the two ranges get compared. Use the constants supplied with every Range object, as shown in the following table.

 

If the first boundary in the comparison occurs earlier in the document than the second boundary, the returned value is -1; if the first boundary comes after the second boundary, the returned value is 1; if the two boundaries are in the identical position, the returned value is 0. Similar to the IE TextRange object's compareEndPoints( ) method.

 

But the situation can be more complex if the boundary points being compared have different ancestor container nodes. The offset values with respect to container nodes influence the comparison results. Due to the variety of results that can occur with numerous relationships between the compared end points, your scripts will need to perform an intricate analysis of boundaries to assure comparisons report the desired sequence. On the other hand, simply looking for unanimity of boundary points is a much simpler prospect. You may prefer to limit your comparisons to looking only for return values of zero (or any other value) for a more binary determination of boundary comparisons.

 
Comparison typeDescription
rng.START_TO_STARTComparing the start position of the current range against the start position of the source range
rng.START_TO_ENDComparing the start position of the current range against the end position of the source range
rng.END_TO_ENDComparing the end position of the current range against the end position of the source range
rng.END_TO_STARTComparing the end poisition of the current range against the start position of the source range
 
Parameters
 
  • Integer values from 0 to 3 corresponding to comparison types. Integer values are not aligned with the W3C DOM standard in Netscape 6 or 7, but the plain-language constants (such as rng.START_TO_START, shown in the table above) produce the correct comparisons.
  • Reference to a second, previously defined Range object, perhaps preserved through the cloneRange( ) method.
 
Returned Value

Integer values -1, 0, or 1.


Powered by Linode.