HTML onselect Attribute: HTML onselect attribute is defined as it fires after some text has been selected in an element. onselect attribute is a part of the Event Attributes. It is supported by many HTML elements such as <input type = “file”>, <input type = “password”>, <input type = “text”>, and <textarea>.
HTML onselect Attribute
The HTML onselect attribute can be applied to all the HTML elements.
Syntax:<element onselect = “script”>
Browser Support
The HTML onselect attribute is supported by the following browsers:
- Chrome
- Firefox
- Opera
- Safari
- Internet Explorer
Example: for <input> element
<!DOCTYPE html> <html> <body> Some text: <input type="text" value="Select me!!" onselect="myFunction()"> <script> function myFunction() { alert("You have selected some text!"); } </script> </body> </html>
Output: