|
|
|
<p id="p1"><b>Hello</b>World</p>oRange.collapse(true) - collapses the range to the beginning
<p id="p1"><b>He|llo</b>World</p>oRange.collapse(false) - collapses the range at the end<p id="p1"><b>Hello</b>Wo|rld</p><p id="p1">Paragraph 1</p><p id="p2">Paragraph 2</p>var oP1 = document.getElementById("p1");var oP2 = document.getElementById("p2");var oRange = document.createRange();oRange.setStartAfter(oP1);oRange.setStartBefore(oP2);alert(oRange.collapsed); //outputs "true"var oNewRange = oRange.cloneRange();compareBoundaryPoints() method on a range object. It takes two arguments: a constant to tell it how to compare and a range to compare to.
Range.START_TO_START (0) - Compares the starting point of the first range to the starting point of the second.Range.START_TO_END (1) - Compares the starting point of the first range to the end point of the second.Range.END_TO_START (2) - Compares the end point of the first range to the end point of the second.Range.END_TO_END (3)Compares the end point of the first range to the start point of the second.oRange.compareBoundaryPoints(Range.START_TO_START, oRange2) - returns 0 - they are equaloRange.compareBoundaryPoints(Range.END_TO_END, oRange2) - returns 1 - point 1 comes after point 2compareBoundaryPoints() result returns the following.
-1 - if the point from the first range comes before the point from the second range.0 - if the points are equal.1 - if the point from the first range comes after the point from the second range.