Interface Selection

A Selection object represents the range of text selected by the user or the current position of the caret. To obtain a Selection object for examination or modification, call Window.getSelection().

MDN Reference

interface Selection {
    anchorNode: null | Node;
    anchorOffset: number;
    focusNode: null | Node;
    focusOffset: number;
    isCollapsed: boolean;
    rangeCount: number;
    type: string;
    addRange(range: Range): void;
    collapse(node: null | Node, offset?: number): void;
    collapseToEnd(): void;
    collapseToStart(): void;
    containsNode(node: Node, allowPartialContainment?: boolean): boolean;
    deleteFromDocument(): void;
    empty(): void;
    extend(node: Node, offset?: number): void;
    getRangeAt(index: number): Range;
    modify(alter?: string, direction?: string, granularity?: string): void;
    removeAllRanges(): void;
    removeRange(range: Range): void;
    selectAllChildren(node: Node): void;
    setBaseAndExtent(anchorNode: Node, anchorOffset: number, focusNode: Node, focusOffset: number): void;
    setPosition(node: null | Node, offset?: number): void;
    toString(): string;
}

Properties

anchorNode: null | Node
anchorOffset: number
focusNode: null | Node
focusOffset: number
isCollapsed: boolean
rangeCount: number
type: string

Methods

  • Parameters

    Returns void

  • Parameters

    • node: null | Node
    • Optionaloffset: number

    Returns void

  • Returns void

  • Returns void

  • Parameters

    • node: Node
    • OptionalallowPartialContainment: boolean

    Returns boolean

  • Returns void

  • Returns void

  • Parameters

    • node: Node
    • Optionaloffset: number

    Returns void

  • Parameters

    • index: number

    Returns Range

  • Parameters

    • Optionalalter: string
    • Optionaldirection: string
    • Optionalgranularity: string

    Returns void

  • Returns void

  • Parameters

    Returns void

  • Parameters

    Returns void

  • Parameters

    • anchorNode: Node
    • anchorOffset: number
    • focusNode: Node
    • focusOffset: number

    Returns void

  • Parameters

    • node: null | Node
    • Optionaloffset: number

    Returns void

  • Returns string