Browser/User Agent Support
| IE | Mozilla | Netscape | Opera | Safari | Netscapte | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
|---|
Constructors
| Constructor | IE | Mozilla | Netscape | Opera | Safari | Netscapte |
|---|---|---|---|---|---|---|
Represents a range of nodes within a document. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Properties
| Property | IE | Mozilla | Netscape | Opera | Safari | Netscapte |
|---|---|---|---|---|---|---|
If true, indicates that the range is collapsed. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Deepest nested node in the document that contains both the start and end points of the range. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Document node that contains the end point of the range. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
End position of the range in the endContainer. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Document node that contains the start point of the range. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Position of the start point of the range in the startContainer. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Methods
| Method | IE | Mozilla | Netscape | Opera | Safari | Netscapte |
|---|---|---|---|---|---|---|
Creates a new DocumentFragment that contains a copy of the document contents for the specified Range. | no | 1.0+ | 7.0+ | 9.0+ | 1.0+ | no |
Creates a copy of the specified Range. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Collapses the Range. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Compares the specified set of boundary points. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Deletes the contents of the document for the specified Range. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Stops the implementation of the range. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Extracts, deletes, and returns the contents of the Range as a DocumentFragment. | no | 1.0+ | 7.0+ | 9.0+ | 1.0+ | no |
Inserts the specified node at the starting point for the Range. | no | 1.0+ | 7.0+ | 9.0+ | 1.0+ | no |
Sets the boundary points of the Range to contain the node and its descendants. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Sets the boundary points of the Range to contain the descendants of a node, but not the actual node. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Sets the end point of the Range as specified by node and offset. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Sets the end point of the range to immediately after the specified node. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Sets the end point of the range to immediately before the specified node. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Sets the start point of the range to the specified position within the specified node. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Sets the start point of the range to immediately after the specified node. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Sets the start point of the range to immediately before the specified node. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Inserts the specified node and makes it a parent to the nodes in the Range. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
Returns the document contents of the Range as a plain text string. | no | 1.0+ | 6.0+ | 9.0+ | 1.0+ | no |
References
Document.createRange | DocumentFragment
Availability
HTML DOM Level 2 | W3C
Constructor Detail
Property Detail
Boolean collapsed - read only
If true, indicates that the range is collapsed.
- Availability
HTML DOM Level 2 | W3C
Node commonAncestorContainer - read only
Deepest nested node in the document that contains both the start and end points of the range.
- Availability
HTML DOM Level 2 | W3C
Node endContainer - read only
Document node that contains the end point of the range.
- Availability
HTML DOM Level 2 | W3C
Number endOffset - read only
End position of the range in the endContainer.
- Availability
HTML DOM Level 2 | W3C
Node startContainer - read only
Document node that contains the start point of the range.
- Availability
HTML DOM Level 2 | W3C
Number startOffset - read only
Position of the start point of the range in the startContainer.
- Availability
HTML DOM Level 2 | W3C
Method Detail
cloneContents() : static DocumentFragment
Creates a new DocumentFragment that contains a copy of the document contents for the specified Range.
- Remarks
- Similar to
extractContents, this method copies the contents of this Range into a newDocumentFragmentbut leaves the original intact. - See Also
DocumentFragment | Range.deleteContents | Range.extractContents
- Availability
HTML DOM Level 2 | W3C
cloneRange() : static Range
Creates a copy of the specified Range.
- Remarks
- Creates a new Range whose boundaries are equal to the current Range.
- See Also
- Availability
HTML DOM Level 2 | W3C
collapse(Boolean toStart) : void
Collapses the Range.
| Boolean | toStart | If true, collapses the Range onto its start; otherwise it collapses on its end. |
- Remarks
- Collapses the Range onto one of its boundary points (e.g. Start or End).
- Availability
HTML DOM Level 2 | W3C
compareBoundaryPoints(Number how, Range sourceRange) : Number
Compares the specified set of boundary points.
| Number | how | Code for how to compare the two boundary points of the range. 0 = START_TO_START, 1 = START_TO_END, 2 = END_TO_END, 3 = END_TO_START. |
| Range | sourceRange | Range to be compared to this range. |
- Remarks
- Compare the boundary points of two Ranges in a document. Similar to the "<=>" compare operator in many languages, it returns -1, 0 or 1 depending on whether the boundary points of the Range is respectively before (-1), equal to (0) or after (1) the corresponding boundary points of the given Range.
- Availability
HTML DOM Level 2 | W3C
deleteContents() : void
Deletes the contents of the document for the specified Range.
- Remarks
- Removes the contents of the Range from its containing
Document(orDocumentFragment). Note that the affected nodes are not returned, but are simply silently removed. - See Also
Node.normalize | Range.cloneContents | Range.extractContents
- Availability
HTML DOM Level 2 | W3C
detach() : void
Stops the implementation of the range.
- Remarks
- Called to indicate that this range is no longer in use, and can be cleaned up. Any subsequent calls to this range will raise a DOMException.
- Availability
HTML DOM Level 2 | W3C
extractContents() : static DocumentFragment
Extracts, deletes, and returns the contents of the Range as a DocumentFragment.
- Remarks
- Moves the contents of the Range from it's containing
Document(orDocumentFragment) into a newDocumentFragment. - See Also
DocumentFragment | Range.cloneContents | Range.deleteContents
- Availability
HTML DOM Level 2 | W3C
insertNode(Node newNode) : void
Inserts the specified node at the starting point for the Range.
| Node | newNode | Node to insert. |
- Remarks
- Inserts a node into the containing
DocumentorDocumentFragmentat the start of the Range. If the container is aTextnode, this will be split at the start of the Range (as if theTextnode'ssplitTextmethod was performed at the insertion point) and insertion will occur between the two resultingTextnodes. AdjacentTextnodes will not be merged. If the given node is aDocumentFragmentnode, its children will be inserted rather than the given node itself. - See Also
- Availability
HTML DOM Level 2 | W3C
selectNode(Node refNode) : void
Sets the boundary points of the Range to contain the node and its descendants.
| Node | refNode | Node to select. |
- Remarks
- Selects the specified node and its contents.
- See Also
- Availability
HTML DOM Level 2 | W3C
selectNodeContents(Node refNode) : void
Sets the boundary points of the Range to contain the descendants of a node, but not the actual node.
| Node | refNode | Node to select the contents of. |
- Remarks
- Selects the contents of the specified node.
- See Also
- Availability
HTML DOM Level 2 | W3C
setEnd(Node refNode, Number offset) : void
Sets the end point of the Range as specified by node and offset.
| Node | refNode | Node at the end of the range. Cannot be null. |
| Number | offset | Value to set the end of the offset at. |
- Remarks
- Sets the end point of a Range.
- Availability
HTML DOM Level 2 | W3C
setEndAfter(Node refNode) : void
Sets the end point of the range to immediately after the specified node.
| Node | refNode | Node to set the end after. |
- Availability
HTML DOM Level 2 | W3C
setEndBefore(Node refNode) : void
Sets the end point of the range to immediately before the specified node.
| Node | refNode | Node to set the end before. |
- Availability
HTML DOM Level 2 | W3C
setStart(Node refNode, Number offset) : void
Sets the start point of the range to the specified position within the specified node.
| Node | refNode | Node for the start point of the range. Cannot be null. |
| Number | offset | Value to set the start of the offset from. |
- Availability
HTML DOM Level 2 | W3C
setStartAfter(Node refNode) : void
Sets the start point of the range to immediately after the specified node.
| Node | refNode | Node to set the start point after. |
- Availability
HTML DOM Level 2 | W3C
setStartBefore(Node refNode) : void
Sets the start point of the range to immediately before the specified node.
| Node | refNode | Node to set the start point before. |
- Availability
HTML DOM Level 2 | W3C
surroundContents(Node newParent) : void
Inserts the specified node and makes it a parent to the nodes in the Range.
| Node | newParent | Node to use as the new parent node. |
- Remarks
- Reparents the contents of the Range to the given node and inserts the node at the position of the start of the Range.
- Availability
HTML DOM Level 2 | W3C
toString() : static String
Returns the document contents of the Range as a plain text string.
- Availability
HTML DOM Level 2 | W3C
