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

MDN Reference

interface Range {
    collapsed: boolean;
    commonAncestorContainer: Node;
    END_TO_END: 2;
    END_TO_START: 3;
    endContainer: Node;
    endOffset: number;
    START_TO_END: 1;
    START_TO_START: 0;
    startContainer: Node;
    startOffset: number;
    cloneContents(): DocumentFragment;
    cloneRange(): Range;
    collapse(toStart?: boolean): void;
    compareBoundaryPoints(how: number, sourceRange: Range): number;
    comparePoint(node: Node, offset: number): number;
    createContextualFragment(string: string): DocumentFragment;
    deleteContents(): void;
    detach(): void;
    extractContents(): DocumentFragment;
    getBoundingClientRect(): DOMRect;
    getClientRects(): DOMRectList;
    insertNode(node: Node): void;
    intersectsNode(node: Node): boolean;
    isPointInRange(node: Node, offset: number): boolean;
    selectNode(node: Node): void;
    selectNodeContents(node: Node): void;
    setEnd(node: Node, offset: number): void;
    setEndAfter(node: Node): void;
    setEndBefore(node: Node): void;
    setStart(node: Node, offset: number): void;
    setStartAfter(node: Node): void;
    setStartBefore(node: Node): void;
    surroundContents(newParent: Node): void;
    toString(): string;
}
Hierarchy
Index

Properties

collapsed: boolean

The read-only collapsed property of the AbstractRange interface returns true if the range's start position and end position are the same.

MDN Reference

commonAncestorContainer: Node

The Range.commonAncestorContainer read-only property returns the deepest — or furthest down the document tree — Node that contains both boundary points of the Range.

MDN Reference

END_TO_END: 2
END_TO_START: 3
endContainer: Node

The read-only endContainer property of the AbstractRange interface returns the Node in which the end of the range is located.

MDN Reference

endOffset: number

The endOffset property of the AbstractRange interface returns the offset into the end node of the range's end position.

MDN Reference

START_TO_END: 1
START_TO_START: 0
startContainer: Node

The read-only startContainer property of the AbstractRange interface returns the start Node for the range.

MDN Reference

startOffset: number

The read-only startOffset property of the AbstractRange interface returns the offset into the start node of the range's start position.

MDN Reference

Methods

  • The cloneContents() method of the Range interface copies the selected Node children of the range's Range/commonAncestorContainer and puts them in a new DocumentFragment object.

    MDN Reference

    Returns DocumentFragment

  • The Range.cloneRange() method returns a The returned clone is copied by value, not reference, so a change in either js-nolint cloneRange() None.

    MDN Reference

    Returns Range

  • The collapse() method of the Range interface collapses the A collapsed Range is empty, containing no content, specifying a single-point in a DOM tree.

    MDN Reference

    Parameters

    • OptionaltoStart: boolean

    Returns void

  • The compareBoundaryPoints() method of the Range interface compares the boundary points of the Range with those of another range.

    MDN Reference

    Parameters

    • how: number
    • sourceRange: Range

    Returns number

  • The comparePoint() method of the Range interface determines whether a specified point is before, within, or after the Range.

    MDN Reference

    Parameters

    • node: Node
    • offset: number

    Returns number

  • The Range.createContextualFragment() method returns a XML fragment parsing algorithm with the start of the range (the parent of the selected node) as the context node.

    MDN Reference

    Parameters

    • string: string

    Returns DocumentFragment

  • The Range.deleteContents() method removes all completely-selected Node within this range from the document.

    MDN Reference

    Returns void

  • The Range.detach() method does nothing.

    MDN Reference

    Returns void

  • The extractContents() method of the Range interface is similar to a combination of Range.cloneContents() and Range.deleteContents().

    MDN Reference

    Returns DocumentFragment

  • The Range.getBoundingClientRect() method returns a DOMRect object that bounds the contents of the range; this is a rectangle enclosing the union of the bounding rectangles for all the elements in the range.

    MDN Reference

    Returns DOMRect

  • The Range.getClientRects() method returns a list of DOMRect objects representing the area of the screen occupied by the range.

    MDN Reference

    Returns DOMRectList

  • The Range.insertNode() method inserts a node at the start of the Range.

    MDN Reference

    Parameters

    Returns void

  • The Range.intersectsNode() method returns a boolean indicating whether the given Node intersects the Range.

    MDN Reference

    Parameters

    Returns boolean

  • The isPointInRange() method of the Range interface determines whether a specified point is within the Range.

    MDN Reference

    Parameters

    • node: Node
    • offset: number

    Returns boolean

  • The Range.selectNode() method sets the the parent of the referenceNode.

    MDN Reference

    Parameters

    Returns void

  • The Range.selectNodeContents() method sets the Range to contain the contents of a Node.

    MDN Reference

    Parameters

    Returns void

  • The Range.setEnd() method sets the end position of a Range to be located at the given offset into the specified node.

    MDN Reference

    Parameters

    • node: Node
    • offset: number

    Returns void

  • The Range.setEndAfter() method sets the end position of a Node of end of the Range will be the same as that for the referenceNode.

    MDN Reference

    Parameters

    Returns void

  • The Range.setEndBefore() method sets the end position of a Range relative to another Node.

    MDN Reference

    Parameters

    Returns void

  • The Range.setStart() method sets the start position of a If the startNode is a Node of type Text, the number of characters from the start of startNode.

    MDN Reference

    Parameters

    • node: Node
    • offset: number

    Returns void

  • The Range.setStartAfter() method sets the start position of a Range relative to a Node.

    MDN Reference

    Parameters

    Returns void

  • The Range.setStartBefore() method sets the start position of a Range relative to another Node.

    MDN Reference

    Parameters

    Returns void

  • The surroundContents() method of the Range interface surrounds the selected content by a provided node.

    MDN Reference

    Parameters

    Returns void

  • Returns a string representation of an object.

    Returns string