HTML event attribute onselect

The onselect attribute event is triggered after selecting text in an element.

What's new in HTML5



<elementName onselect="script">

Supported Tags

<input type="file">, 
<input type="password">, 
<input type="text">, 

Browser compatibility

onselect Yes Yes Yes Yes Yes


<!DOCTYPE html>
<!-- www.  j a v a2s  .  co m-->
Some text: <input type="text" value="Select me!!" onselect="myFunction()">

function myFunction() {
    console.log("You have selected some text!");


Click to view the demo