YouTip LogoYouTip

Ev Onselect

## HTML onselect Event Attribute The `onselect` event attribute fires immediately after a user selects (highlights) some text inside a text-based form element. --- ## Browser Support The `onselect` attribute is universally supported across all major modern web browsers: * Google Chrome * Mozilla Firefox * Microsoft Edge / Internet Explorer * Safari * Opera --- ## Definition and Usage The `onselect` attribute is triggered when a user selects text within specific input elements. ### Supported Elements The `onselect` attribute can only be used on the following HTML elements: * `` * `` * `` * `

``` --- ## Technical Considerations * **Selection Range:** When handling the `select` event in JavaScript, you can retrieve the exact text selected by the user using the `selectionStart` and `selectionEnd` properties of the input element (as demonstrated in Example 2). * **Global Text Selection:** The HTML `onselect` attribute only applies to form input elements. If you need to detect text selection anywhere else on a webpage (such as within `

` or `

` tags), you should use the standard JavaScript `document.onselectionchange` event or the `window.getSelection()` API.
← Ev OnsubmitEv Onfocus β†’