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: Node;
        anchorOffset: number;
        direction: string;
        focusNode: Node;
        focusOffset: number;
        isCollapsed: boolean;
        rangeCount: number;
        type: string;
        addRange(range: Range): void;
        collapse(node: 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: Node, offset?: number): void;
        toString(): string;
    }

    Properties

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

    Methods

    • Parameters

      • node: Node
      • Optionaloffset: number

      Returns void

    • Parameters

      • node: Node
      • OptionalallowPartialContainment: boolean

      Returns boolean

    • Parameters

      • node: Node
      • Optionaloffset: number

      Returns void

    • Parameters

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

      Returns void

    • Parameters

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

      Returns void

    • Parameters

      • node: Node
      • Optionaloffset: number

      Returns void

    • Returns string