Friday, December 17, 2010

collapse() in Ran

A good explanation of JavaScript DOM ranges...

Collapsing a DOM Range

To empty a range, (that is, to have it select no part of the document), you collapse it. Collapsing a range resembles the behavior of a text box. When you have text in a text box, you can highlight an entire word using the mouse. However, if you left-click the mouse again, the selection is removed and the cursor is located between two letters. When you collapse a range, you are setting its locations between parts of a document, either at the beginning of the range selection or at the end. Figure 6 illustrates what happens when a range is collapsed.
JavaScript DOM Ranges : Figure 6
Figure 6You can collapse a range by using the collapse() method, which accepts a single argument: a Boolean value indicating which end of the range to collapse to. If the argument is true, then the range is collapsed to its starting point; if false, the range is collapsed to its ending point. To determine if a range is collapsed, you can use the collapsed property:
oRange.collapse(true);      //collapse to the starting point
alert(oRange.collapsed);    //outputs "true"
How to do range highlighting too:

No comments:

Post a Comment