Open In App
Related Articles

HTML onsearch Event Attribute

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

This onsearch attribute works when a user presses the ENTER button or clicks on the x button. This event works with <input> element.

Supported Tags: 

Syntax: 

<element onsearch="script">

Attribute: This event contains single attribute script which contains the script to be run when event call.

Example: 

html

<!DOCTYPE html>
<html>
 
<head>
    <title>onsearch event</title>
    <style>
        .gfg {
            font-size:40px;
            color:green;
            font-weight:bold;
        }
        body {
            text-align:center;
        }
    </style>
</head>
 
<body>
 
    <div class="gfg">
      GeeksforGeeks
      </div>
    <h2>onsearch event attribute</h2>
    <input type="search"
           id="geeks"
           onsearch="geeksforgeeks()">
     
    <p id="geek"></p>
 
    <script>
        function geeksforgeeks() {
            let x = document.getElementById("geeks");
            document.getElementById("geek").innerHTML =
                   "Searching Content: " + x.value;
        }
    </script>
</body>
 
</html>

                    

Output: 


Supported Browsers: The browsers supported by onsearch Event Attribute are listed below: 
 

  • Apple Safari 2
  • Google Chrome 1
  • Edge 79
  • Opera 15


Last Updated : 04 Aug, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads