This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

getSelection

Summary

Returns a Selection object that represents the current selection of the document.

Method of dom/Windowdom/Window

Syntax

var selection = window.getSelection();

Return Value

Returns an object of type ObjectObject

A Selection object that represents the currently selected text in the window.

Examples

function foo() {
    var selObj = window.getSelection();
    alert(selObj);
    var selRange = selObj.getRangeAt(0);
    // do stuff with the range
}

Standards information

Attributions