Range

js.html.Range (extern class)

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

Documentation Range by Mozilla Contributors, licensed under CC-BY-SA 2.5.

See:

Static Members

START_TO_START: Int

START_TO_END: Int

END_TO_END: Int

END_TO_START: Int

Instance Members

startContainer: Node

Returns the Node within which the Range starts.


startOffset: Int

Returns a number representing where in the startContainer the Range starts.


endContainer: Node

Returns the Node within which the Range ends.


endOffset: Int

Returns a number representing where in the endContainer the Range ends.


collapsed: Bool

Returns a Boolean indicating whether the range's start and end points are at the same position.


commonAncestorContainer: Node

Returns the deepest Node that contains the startContainer and endContainer nodes.


setStart(refNode: Node, offset: Int): Void

Sets the start position of a Range.

Name Type
refNode Node
offset Int

setEnd(refNode: Node, offset: Int): Void

Sets the end position of a Range.

Name Type
refNode Node
offset Int

setStartBefore(refNode: Node): Void

Sets the start position of a Range relative to another Node.

Name Type
refNode Node

setStartAfter(refNode: Node): Void

Sets the start position of a Range relative to another Node.

Name Type
refNode Node

setEndBefore(refNode: Node): Void

Sets the end position of a Range relative to another Node.

Name Type
refNode Node

setEndAfter(refNode: Node): Void

Sets the end position of a Range relative to another Node.

Name Type
refNode Node

collapse(?toStart: Bool = false): Void

Collapses the Range to one of its boundary points.

Name Type Default
toStart Bool false

selectNode(refNode: Node): Void

Sets the Range to contain the Node and its contents.

Name Type
refNode Node

selectNodeContents(refNode: Node): Void

Sets the Range to contain the contents of a Node.

Name Type
refNode Node

compareBoundaryPoints(how: Int, sourceRange: Range): Int

Compares the boundary points of the Range with another Range.

Name Type
how Int
sourceRange Range
Returns
Int

deleteContents(): Void

Removes the contents of a Range from the Document.


extractContents(): DocumentFragment

Moves contents of a Range from the document tree into a DocumentFragment.

Returns
DocumentFragment

cloneContents(): DocumentFragment

Returns a DocumentFragment copying the nodes of a Range.

Returns
DocumentFragment

insertNode(node: Node): Void

Insert a Node at the start of a Range.

Name Type
node Node

surroundContents(newParent: Node): Void

Moves content of a Range into a new Node.

Name Type
newParent Node

cloneRange(): Range

Returns a Range object with boundary points identical to the cloned Range.

Returns
Range

detach(): Void

Releases the Range from use to improve performance.


isPointInRange(node: Node, offset: Int): Bool

Returns a boolean indicating whether the given point is in the Range.

Name Type
node Node
offset Int
Returns
Bool

comparePoint(node: Node, offset: Int): Int

Returns -1, 0, or 1 indicating whether the point occurs before, inside, or after the Range.

Name Type
node Node
offset Int
Returns
Int

intersectsNode(node: Node): Bool

Returns a boolean indicating whether the given node intersects the Range.

Name Type
node Node
Returns
Bool

createContextualFragment(fragment: String): DocumentFragment

Returns a DocumentFragment created from a given string of code.

Name Type
fragment String
Returns
DocumentFragment

getClientRects(): DOMRectList

Returns a list of DOMRect objects that aggregates the results of Element.getClientRects() for all the elements in the Range.

Returns
DOMRectList

getBoundingClientRect(): DOMRect

Returns a DOMRect object which bounds the entire contents of the Range; this would be the union of all the rectangles returned by range.getClientRects().

Returns
DOMRect

new(): Void