Note: This API is not available in Web Workers (not exposed via WorkerNavigator
).
The Selection API enables developers to access and manipulate the portion of a document selected by the user.
The Window.getSelection()
and Document.getSelection()
methods return a Selection
object representing the portion of the document selected by the user. A Selection
object provides methods to:
- access the currently selected nodes
- modify the current selection, expanding or collapsing it or selecting an entirely different part of the document
- delete parts of the current selection from the DOM.
The Selection API also provides two events, both firing on Document
:
- the
selectstart
event is fired when the user starts to make a new selection - the
selectionchange
event is fired when the current selection changes.