This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The Selection.toString() method returns a string currently being represented by the selection object, i.e. the currently selected text.

Syntax

str = sel.toString()

Return value

  • str is the string representation of selection.

Parameters

None.

Description

This method returns the currently selected text.

In JavaScript, this method is called automatically when a function the selection object is passed to requires a string:

alert(window.getSelection()) // What is called
alert(window.getSelection().toString())  // What is actually being effectively called.

Specifications

Specification Status Comment
HTML Editing APIs
The definition of 'Selection.toString()' in that specification.
Editor's Draft Initial definition

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic support
Experimental
Chrome ? Edge Full support YesFirefox Full support YesIE ? Opera ? Safari ? WebView Android ? Chrome Android ? Edge Mobile Full support YesFirefox Android Full support YesOpera Android ? Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.

See also

Document Tags and Contributors

Last updated by: connorshea,