I volontari di MDN non hanno ancora tradotto questo articolo in Italiano. Unisciti a noi e traducilo tu stesso.
Puoi anche consultare l’articolo in 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

Tag del documento e collaboratori

Hanno collaborato alla realizzazione di questa pagina: mfluehr, fscholz, DGruenwald, teoli, klez, Sheppy, ethertank, Yuan.Xulei, louisremi
Ultima modifica di: mfluehr,