Get to know MDN better
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:
The Selection API also provides two events, both firing on Document:
An interface which represents the part of the document selected by the user or the current position of the caret.
Document.getSelection()A method returning a Selection object representing the current selection or current position of the caret.
Window.getSelection()A method returning a Selection object representing the current selection or current position of the caret.
Document.selectionchangeAn event which is fired when the current selection is changed.
Node.selectstartAn event which is fired when a user starts a new selection.
| Selection API # selection-interface |
This page was last modified on Jul 26, 2024 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.