Avustajamme eivät ole vielä kääntäneet tätä artikkelia kielelle suomi. Liity yhteisöömme ja hoida homma kuntoon!
Voit myös lukea tämän artikkelin kielellä English (US).

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


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.



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


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);



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

See also

Document Tags and Contributors

Viimeksi päivittänyt: mfluehr,