Nageshwar Reddy Pandem
Nageshwar Reddy Pandem

Reputation: 1047

Any event for reset button on click of input type=search?

Is there any event available for clicking reset button appears on html5 search input element?

Upvotes: 0

Views: 5637

Answers (1)

jdabrowski
jdabrowski

Reputation: 1975

The event is called search. It is fired on both: the search and the reset. You just need to check if the query is empty or not.

For example:

$("#searchInput").on("search", function(evt){
    if($(this).val().length > 0){
        // the search is being executed
    }else{
        // user clicked reset
    }
});

It works, here is the fiddle: https://fiddle.jshell.net/ye1dabap/

Upvotes: 8

Related Questions