Unsere Freiwilligen haben diesen Artikel noch nicht in Deutsch übersetzt. Machen Sie mit und helfen Sie, das zu erledigen!
Sie können den Artikel auch auf English (US) lesen.

The select event fires when some text has been selected.

The event is not available for all elements in all languages. For example, in HTML, select events can be dispatched only on form <input type="text"> and <textarea> elements.

General info

Interface UIEvent if generated from a user interface, Event otherwise
Bubbles Yes
Cancelable No
Target Element
Default Action None

Properties

Property Type Description
target Read only EventTarget The event target (the topmost target in the DOM tree).
type Read only DOMString The type of event.
bubbles Read only Boolean Whether the event normally bubbles or not.
cancelable Read only Boolean Whether the event is cancellable or not.
view Read only WindowProxy Document.defaultView (window of the document)
detail Read only long (float) 0.

Example

HTML

<input value="Try selecting some text in this element.">
<p id="log"></p>

JavaScript

function logSelection(event) {
  const log = document.getElementById('log');
  const selection = event.target.value.substring(event.target.selectionStart, event.target.selectionEnd);
  log.textContent = `You selected: ${selection}`;
}

const input = document.querySelector('input');
input.addEventListener('select', logSelection);

Result

Specifications

Specification Status Comment
UI Events
The definition of 'select' in that specification.
Working Draft  

See also

Schlagwörter des Dokuments und Mitwirkende

Mitwirkende an dieser Seite: mfluehr, fscholz, DGruenwald, teoli, klez, Sheppy, ethertank, Yuan.Xulei, louisremi
Zuletzt aktualisiert von: mfluehr,