HTML | DOM onselect Event
The onselect event in HTML DOM occurs when user selects some text in an element. This event is mostly used in <textarea> and <input> tag.
Syntax:
- In HTML:
<element onselect="Script">
- In JavaScript:
object.onselect = function(){Script}; - In JavaScript, using the addEventListener() method:
object.addEventListener("select", Script); - Google Chrome
- Internet Explorer
- Firefox
- Apple Safari
- Opera
- HTML | onselect Event Attribute
- HTML | DOM ondrop Event
- HTML | DOM onended Event
- HTML | DOM ondurationchange Event
- HTML | DOM onseeking Event
- HTML | DOM animationend Event
- HTML | DOM ondragover Event
- HTML | DOM onfocus Event
- HTML | DOM oninvalid Event
- HTML | DOM onafterprint Event
- HTML | DOM ondragstart Event
- HTML | DOM ondblclick Event
- HTML | DOM oncut Event
- HTML | DOM onerror Event
- HTML | DOM Storage Event
Example: Using the addEventListener() method
<!DOCTYPE html> <html> <head> <title> HTML DOM onselect Event </title> </head> <body> <center> <h1 style="color:green"> GeeksforGeeks </h1> <h2>HTML DOM onselect Event</h2> Email: <input type="email" value="feedback@geeksforgeeks.org" id="mailID"> <p id="try"></p> </center> <script> document.getElementById( "mailID").addEventListener( "select", GFGfun); function GFGfun() { document.getElementById( "try").innerHTML = "Selected"; } </script> </body> </html> |
chevron_right
filter_none
Output:
Before:

After:

Supported Browsers: The browsers supported by HTML DOM onselect Event are listed below:
Recommended Posts:
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



