Skip to content
Related Articles

Related Articles

Improve Article
HTML | onselect Event Attribute
  • Difficulty Level : Basic
  • Last Updated : 15 Oct, 2020

The onselect event attribute works when some text has been selected in an element. It is the part of event attribute. It is supported by many HTML elements such as <input type = “file”>, <input type = “password”>, <input type = “text”>, and <textarea>.

Syntax: 

<element onselect = "script">




Example: 

HTML




<!DOCTYPE html>
<html>
    <head>
        <title>onselect event attribute</title>
        <style>
            h1 {
            color:green;
            }
            body {
                text-align:center;
            }
        </style>
        <script>
            function Geeks() {
                alert("Text selected!");
            }
        </script>
    </head>
    <body>
        <h1>GeeksforGeeks</h1>
        <h2>onselect event attribute</h2>
        Text Box: <input type="text" value="GeeksforGeeks: A computer
        science portal for geeks" onselect="Geeks()">
    </body>
</html>                   
</html>

Output: 

Supported Browsers: The browser supported by onselect attribute are listed below: 

  • Apple Safari
  • Google Chrome
  • Firefox
  • Opera
  • Internet Explorer
My Personal Notes arrow_drop_up
Recommended Articles
Page :