Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. Document
  4. selectionchange

Document: selectionchange event

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.

Theselectionchange event of theSelection API is fired when the currentSelection of aDocument is changed.

This event is not cancelable and does not bubble.

The event can be handled by adding an event listener forselectionchange or using theonselectionchange event handler.

Note:This event is not quite the same as theselectionchange events fired when the text selection in an<input> or<textarea> element is changed. See theselectionchange event ofHTMLInputElement for more details.

Syntax

Use the event name in methods likeaddEventListener(), or set an event handler property.

js
addEventListener("selectionchange", (event) => { })onselectionchange = (event) => { }

Event type

A genericEvent.

Examples

js
// addEventListener versiondocument.addEventListener("selectionchange", () => {  console.log(document.getSelection());});// onselectionchange versiondocument.onselectionchange = () => {  console.log(document.getSelection());};

Specifications

Specification
Selection API
# selectionchange-event
Selection API
# dom-globaleventhandlers-onselectionchange

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp