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
- HTML5 A vocabulary and associated APIs for HTML and XHTML, Section 6.6.1
Attributions
Mozilla Developer Network : [getSelection Article]
Microsoft Developer Network: [getSelection Method Article]