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 onselect property of the GlobalEventHandlers mixin is an EventHandler that processes select events.

The select event only fires after text inside an <input type="text"> or <textarea> is selected.


target.onselect = functionRef;


functionRef is a function name or a function expression. The function receives a UIEvent object as its sole argument.


This example logs the text you select inside a <textarea> element.


<textarea>Try selecting some text in this element.</textarea>
<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 textarea = document.querySelector('textarea');
textarea.onselect = logSelection;



Specification Status Comment
HTML Living Standard
The definition of 'onselect' in that specification.
Living Standard  

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
onselectChrome Full support YesEdge Full support YesFirefox Full support YesIE ? Opera ? Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android ? Safari iOS ? Samsung Internet Android ?


Full support  
Full support
Compatibility unknown  
Compatibility unknown

See also

Tag del documento e collaboratori

Hanno collaborato alla realizzazione di questa pagina: chrisdavidmills, mdnwebdocs-bot, mfluehr, fscholz, erikadoyle, jpmedley, cvrebert, teoli, kscarfone, Sheppy, ziyunfei, Jabez, Nickolay, Mw22, alecananian
Ultima modifica di: chrisdavidmills,