How do you detect the clearing of a "search" HTML5 input?

Jason picture Jason · Jun 4, 2010 · Viewed 99.8k times · Source

In HTML5, the search input type appears with a little X on the right that will clear the textbox (at least in Chrome, maybe others). Is there a way to detect when this X is clicked in Javascript or jQuery other than, say, detecting when the box is clicked at all or doing some sort of location click-detecting (x-position/y-position)?

Answer

Pauan picture Pauan · Sep 16, 2010

Actually, there is a "search" event that is fired whenever the user searches, or when the user clicks the "x". This is especially useful because it understands the "incremental" attribute.

Now, having said that, I'm not sure if you can tell the difference between clicking the "x" and searching, unless you use an "onclick" hack. Either way, hopefully this helps.

References:

http://help.dottoro.com/ljdvxmhr.php