Range : Object

Represents a range of nodes within a document.

Browser/User Agent Support

IEMozillaNetscapeOperaSafariNetscapte
no1.0+6.0+9.0+1.0+no

Constructors

ConstructorIEMozillaNetscapeOperaSafariNetscapte
Represents a range of nodes within a document.
no1.0+6.0+9.0+1.0+no
 

Properties

PropertyIEMozillaNetscapeOperaSafariNetscapte
If true, indicates that the range is collapsed.
no1.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.
no1.0+6.0+9.0+1.0+no
 
Document node that contains the end point of the range.
no1.0+6.0+9.0+1.0+no
 
End position of the range in the endContainer.
no1.0+6.0+9.0+1.0+no
 
Document node that contains the start point of the range.
no1.0+6.0+9.0+1.0+no
 
Position of the start point of the range in the startContainer.
no1.0+6.0+9.0+1.0+no
 

Methods

MethodIEMozillaNetscapeOperaSafariNetscapte
Creates a new DocumentFragment that contains a copy of the document contents for the specified Range.
no1.0+7.0+9.0+1.0+no
 
Creates a copy of the specified Range.
no1.0+6.0+9.0+1.0+no
 
Collapses the Range.
no1.0+6.0+9.0+1.0+no
 
Compares the specified set of boundary points.
no1.0+6.0+9.0+1.0+no
 
Deletes the contents of the document for the specified Range.
no1.0+6.0+9.0+1.0+no
 
Stops the implementation of the range.
no1.0+6.0+9.0+1.0+no
 
Extracts, deletes, and returns the contents of the Range as a DocumentFragment.
no1.0+7.0+9.0+1.0+no
 
Inserts the specified node at the starting point for the Range.
no1.0+7.0+9.0+1.0+no
 
Sets the boundary points of the Range to contain the node and its descendants.
no1.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.
no1.0+6.0+9.0+1.0+no
 
Sets the end point of the Range as specified by node and offset.
no1.0+6.0+9.0+1.0+no
 
Sets the end point of the range to immediately after the specified node.
no1.0+6.0+9.0+1.0+no
 
Sets the end point of the range to immediately before the specified node.
no1.0+6.0+9.0+1.0+no
 
Sets the start point of the range to the specified position within the specified node.
no1.0+6.0+9.0+1.0+no
 
Sets the start point of the range to immediately after the specified node.
no1.0+6.0+9.0+1.0+no
 
Sets the start point of the range to immediately before the specified node.
no1.0+6.0+9.0+1.0+no
 
Inserts the specified node and makes it a parent to the nodes in the Range.
no1.0+6.0+9.0+1.0+no
 
Returns the document contents of the Range as a plain text string.
no1.0+6.0+9.0+1.0+no
 

References

Document.createRange | DocumentFragment

Availability

HTML DOM Level 2 | W3C

Constructor Detail

Range Range()

Represents a range of nodes within a document.

Visibility
internal

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 new DocumentFragment but 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

Document.createRange

Availability

HTML DOM Level 2 | W3C

collapse(Boolean toStart) : void

Collapses the Range.

BooleantoStartIf 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.

NumberhowCode 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.
RangesourceRangeRange 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 (or DocumentFragment). 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 (or DocumentFragment) into a new DocumentFragment.
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.

NodenewNodeNode to insert.

Remarks
Inserts a node into the containing Document or DocumentFragment at the start of the Range. If the container is a Text node, this will be split at the start of the Range (as if the Text node's splitText method was performed at the insertion point) and insertion will occur between the two resulting Text nodes. Adjacent Text nodes will not be merged. If the given node is a DocumentFragment node, its children will be inserted rather than the given node itself.
See Also

DocumentFragment | Node.normalize

Availability

HTML DOM Level 2 | W3C

selectNode(Node refNode) : void

Sets the boundary points of the Range to contain the node and its descendants.

NoderefNodeNode to select.

Remarks
Selects the specified node and its contents.
See Also

Range.selectNodeContents

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.

NoderefNodeNode to select the contents of.

Remarks
Selects the contents of the specified node.
See Also

Range.selectNode

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.

NoderefNodeNode at the end of the range. Cannot be null.
NumberoffsetValue 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.

NoderefNodeNode 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.

NoderefNodeNode 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.

NoderefNodeNode for the start point of the range. Cannot be null.
NumberoffsetValue 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.

NoderefNodeNode 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.

NoderefNodeNode 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.

NodenewParentNode 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