/

HTML / CSS / JavaScript Tutorial

JavaScript Window method: getSelection()

[this page | pdf | back links]

The getSelection() method (when applied to Window objects in the JavaScript BOM) returns an object representing the range of text selected by user.

 

Note: one way of returning the text selected is to cast the result to a string (either by appending an empty string or by applying the toString() method to the object).

 

It has the following syntax with no parameters. It returns a Selection object.

 

window.getSelection()

 


NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)


Desktop view | Switch to Mobile