JavaScript Bible, Gold Edition part 59. This book will bring programmers and non-technical professionals, including casual programmers and scripters, painlessly up to speed on all aspects of mastering JavaScript. Key topics include programming fundamentals, JavaScript language elements and how to use them effectively, and how to easily and efficiently add powerful new functionality to HTML documents and Java applets. | 428 Part III Document Objects Reference var rng Note The first release of NN6 requires that a newly created range be more explicitly defined as described in a moment before scripts can access the range s properties. The W3C DOM however suggests that a new range has as its containing node the document node which encompasses all content of the page including the HTML tag set . Moreover the start and end points are set initially to zero meaning that the initial range is collapsed at the very beginning of the document. With an active range stored in a variable you can use many of the object s methods to adjust the start and end points of the range. If the range is to consist of all of the contents of a node you have two convenience methods that do so from different points of view selectNode and selectNodeContents . The sole parameter passed with both methods is a reference to the node whose contents you want to turn into a range. The difference between the two methods is how the offset properties of the range are calculated as a result see the discussion about these methods later in the chapter for details . Another series of methods setStartBefore setStartAfter setEndBefore and setEndAfter let you adjust each end point individually to a position relative to a node boundary. For the most granular adjustment of boundaries the setStart and setEnd methods let you specify a reference node where to start counting the offset and the offset integer value. If you need to select an insertion point for example to insert some content into an existing node you can position either end point where you want it and then invoke the collapse method. A parameter determines whether the collapse should occur at the range s start or end point. A suite of other methods lets your scripts work with the contents of a range directly. You can copy cloneContents delete deleteContents extractContents insert a node insertNode and even surround a range s contents with a new .