This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

Range

Summary

The Range interface represents a fragment of a document that can contain nodes and parts of text nodes in a given document.

Properties

collapsed
The Range.collapsed read-only property returns a Boolean flag indicating whether the start and end points of the Range are at the same position. It returns true if the start and end boundary points of the Range are the same point in the DOM, false if not.
commonAncestorContainer
Returns the deepest node in which two boundary points exist.
endContainer
Retrieves the end point node of the current range.
endOffset
Returns a number representing where in the Range.endContainer the Range ends.
startContainer
Retrieves the starting node of a current range
startOffset
Retrieves the offset of the starting boundary point relative to the startContainer in the current range.

Methods

cloneContents
Returns a document fragment containing the nodes of a range. If any nodes are partially selected, their start or end nodes are included.
cloneRange
Returns a new range with boundary points that are equal to the original range.
collapse
Collapses (or removes) a range by moving the insertion point to the beginning or end of the current range.
compareBoundaryPoints
The Range.compareBoundaryPoints() method compares the boundary points of the Range with another one.
deleteContents
Removes all contents within a selected range.
detach
Removes or detaches a Range object and associated resources form a document.
extractContents
Removes the contents of a range from a document or document fragment and puts it a new document fragment.
insertNode
Inserts a Node into the start of a Range object.
selectNode
Selects a range node and all of its contents.
selectNodeContents
Sets the Range to contain the contents of a Node.
setEnd
Sets the end point of the range.
setEndAfter
Sets the end of a range to a point after a specific node.
setEndBefore
Sets the end of the range to a point before a specific node.
setStart
Sets the starting point of a range
setStartAfter
Sets the starting point of the range to a point after a specific node.
setStartBefore
Sets the start point of a range to a point before a specific node.
surroundContents
Moves the contents of a Range to a new parent node, placing the new parent node at the start position of the Range.
toString
Returns the contents of a Range as a string. This string contains only the data characters, no markup.

Events

No events.

Standards information

Related specifications

CSS Object Model - View Module
Working Draft
DOM Parsing and Serialization
Living Standard
DOM
Living Standard

Attributions

  • Mozilla Developer Network cc-by-sa-small-wpd.svg: [Range Article]

  • Microsoft Developer Network: [Range Article]