Web/API/GlobalEventHandlers/onselect

From Get docs


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.

Syntax

target.onselect = functionRef;

Value

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

Examples

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

HTML

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

Result

Specification

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

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
onselect Chrome

Full support Yes

Edge

Full support ≤18

Firefox

Full support Yes

IE

?

Opera

?

Safari

?

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android

Full support Yes

Opera Android

?

Safari iOS

?

Samsung Internet Android

Full support Yes

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown


See also