Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. Selection API

Selection API

Note:This API isnot available inWeb Workers (not exposed viaWorkerNavigator).

TheSelection API enables developers to access and manipulate the portion of a document selected by the user.

TheWindow.getSelection() andDocument.getSelection() methods return aSelection object representing the portion of the document selected by the user. ASelection 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 onDocument:

  • theselectstart event is fired when the user starts to make a new selection
  • theselectionchange event is fired when the current selection changes.

Interfaces

Selection

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 aSelection object representing the current selection or current position of the caret.

Window.getSelection()

A method returning aSelection object representing the current selection or current position of the caret.

Document.selectionchange

An event which is fired when the current selection is changed.

Node.selectstart

An event which is fired when a user starts a new selection.

Specifications

Specification
Selection API
# selection-interface

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp