# Range : Object
Return to: HTML DOM Level 2 index

Represents a range of nodes within a document.

## Platform Support

IE | Mozilla | Netscape | Opera | Safari
--- | --- | --- | --- | ---
no | 1.0+ | 6.0+ | 9.0+ | 1.0+

## Constructors

Constructor | Action | IE | Mozilla | Netscape | Opera | Safari
--- | --- | --- | --- | --- | --- | ---
Range Constructor() : Range Represents a range of nodes within a document. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

### Range() : Range

Represents a range of nodes within a document.

Returns

Range |

Visibility
  internal

## Properties

Property | Action | IE | Mozilla | Netscape | Opera | Safari
--- | --- | --- | --- | --- | --- | ---
collapsed : Boolean If true, indicates that the range is collapsed. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Availability

  HTML DOM Level 2|W3C

commonAncestorContainer : Node Deepest nested node in the document that contains both the start and end points of the range. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Availability

  HTML DOM Level 2|W3C

endContainer : Node Document node that contains the end point of the range. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Availability

  HTML DOM Level 2|W3C

endOffset : Number End position of the range in the endContainer. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Availability

  HTML DOM Level 2|W3C

startContainer : Node Document node that contains the start point of the range. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Availability

  HTML DOM Level 2|W3C

startOffset : Number Position of the start point of the range in the startContainer. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Availability

  HTML DOM Level 2|W3C

## Functions

Method | Action | IE | Mozilla | Netscape | Opera | Safari
--- | --- | --- | --- | --- | --- | ---
static cloneContents() : DocumentFragment Creates a new DocumentFragment that contains a copy of the document contents for the specified Range. | Show Details | no | 1.0+ | 7.0+ | 9.0+ | 1.0+

Returns

DocumentFragment |

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

static cloneRange() : Range Creates a copy of the specified Range. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Returns

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. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Parameters

Boolean | toStart | If true, collapses the Range onto its start; otherwise it collapses on its end.

Returns

void |

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. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Parameters

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.

Returns

Number |

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. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Returns

void |

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. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Returns

void |

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

static extractContents() : DocumentFragment Extracts, deletes, and returns the contents of the Range as a DocumentFragment. | Show Details | no | 1.0+ | 7.0+ | 9.0+ | 1.0+

Returns

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. | Show Details | no | 1.0+ | 7.0+ | 9.0+ | 1.0+

Parameters

Node | newNode | Node to insert.

Returns

void |

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. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Parameters

Node | refNode | Node to select.

Returns

void |

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. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Parameters

Node | refNode | Node to select the contents of.

Returns

void |

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. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Parameters

Node | refNode | Node at the end of the range. Cannot be null.
Number | offset | Value to set the end of the offset at.

Returns

void |

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. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Parameters

Node | refNode | Node to set the end after.

Returns

void |

Availability

  HTML DOM Level 2|W3C

setEndBefore(Node refNode) : void Sets the end point of the range to immediately before the specified node. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Parameters

Node | refNode | Node to set the end before.

Returns

void |

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. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Parameters

Node | refNode | Node for the start point of the range. Cannot be null.
Number | offset | Value to set the start of the offset from.

Returns

void |

Availability

  HTML DOM Level 2|W3C

setStartAfter(Node refNode) : void Sets the start point of the range to immediately after the specified node. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Parameters

Node | refNode | Node to set the start point after.

Returns

void |

Availability

  HTML DOM Level 2|W3C

setStartBefore(Node refNode) : void Sets the start point of the range to immediately before the specified node. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Parameters

Node | refNode | Node to set the start point before.

Returns

void |

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. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Parameters

Node | newParent | Node to use as the new parent node.

Returns

void |

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

static toString() : String Returns the document contents of the Range as a plain text string. | Show Details | no | 1.0+ | 6.0+ | 9.0+ | 1.0+

Returns

String |

Availability

  HTML DOM Level 2|W3C

## References

Document.createRange|DocumentFragment

## Availability

HTML DOM Level 2|W3C

text_javascript aptana_docs