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.
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.
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 |
---|
HTML Standard # handler-onselect |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
onselect |
1 |
12 |
9 |
9 |
≤12.1 |
1 |
1 |
18 |
9 |
≤12.1 |
1 |
1.0 |
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onselect