HTML onselect Event Attribute

Description

The event attribute onselect allows you to set the script to fire when text is selected in an element.

Syntax

<element onselect="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE html> 
  <html> 
    <head>
      <title>onselect event</title> 
    </head> 
    <body> 
    <textarea rows="5" cols="40" onselect="testFunction()">You just need to select the text to run the script ...</textarea> 
<script> 
function testFunction () { 
  alert ( "You ran the script!" ); 
} 
</script> 
  </body> 
</html>

Supported Tags

<input>, <keygen> and <textarea>

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
XYesYesYesXX
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
YesYesYesXXX