HTML event attribute onsearch

The onsearch attribute event is triggered when a user does the search by pressing the ENTER key in an <input> element with type="search".

We can also trigger the event by clicking 'X' inside the field.

What's new in HTML5



<elementName onsearch="script">

Supported Tags

<input type="search">

Browser compatibility

onsearch Yes No No Yes Yes


<!DOCTYPE html>
<!--from w w  w  .j a  v a  2 s. c o  m-->
<input type="search" id="myInput" onsearch="myFunction()">

function myFunction() {
   var x = document.getElementById("myInput");


Click to view the demo