GlobalEventHandlers.onselect
The onselect
property of the
GlobalEventHandlers
mixin is an event handler 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
Specifications
Specification |
---|
HTML Standard # handler-onselect |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
onselect | ChromeFull support1 | EdgeFull support12 | FirefoxFull support9 | Internet ExplorerFull support9 | OperaFull support12.1 | SafariFull support1 | WebView AndroidFull support1 | Chrome AndroidFull support18 | Firefox for AndroidFull support9 | Opera AndroidFull support12.1 | Safari on iOSFull support1 | Samsung InternetFull support1.0 |
Legend
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.