Easy Tutorial
❮ Prop Textarea Require Prop Datetime Local Required ❯

Window getSelection() Method


Definition and Usage

The getSelection() method represents the text range selected by the user or the current position of the cursor.

Syntax

window.getSelection();

Browser Support

All major browsers support the focus() method.


Example

Read the selected content:

function foo() {
    let selObj = window.getSelection();
    alert(selObj.toString());
}

❮ Prop Textarea Require Prop Datetime Local Required ❯