In HTML5 there is a new input type, 'search'. On most browser it's just remain to a simple 'text' input, but for webkit based browsers, it adds a little cross to reset the input.
I'd like to be able to handle this, is there an event for that ?
In HTML5 there is a new input type, 'search'. On most browser it's just remain to a simple 'text' input, but for webkit based browsers, it adds a little cross to reset the input.
I'd like to be able to handle this, is there an event for that ?
At first glance, I would say no there is not a way to capture it.
http://www.w3schools.com/html5/tag_input.asp
There appears to be no listed event for it since it shares events with all of other input types.
That being said, you could always just step through it in a browser and inspect the event object for some kind of identifier. Different browsers might handle it differently however.
No, it's not possible. This UI interaction is some goodness that webkit implements, but is not actually specced. See here. So even if it were possible--you can't expect this UI to be implemented in Gecko, for example, if and when they ever add type=search.
I don't know that this is the correct answer, but the click
event handler is called when the user clears the input using the X button.
$('input[type="search"]').click(function(event) {
// This code runs anytime a user clicks on the input,
// including when they clear it using the X button.
})
It seems miketaylr is correct, it isn't possible to catch this event. See the answer for this question: http://stackoverflow.com/questions/2977023/how-do-you-detect-the-clearing-of-a-search-html5-input
For the sake of being standards-compliant and not relying on one feature of one layout engine, I suggest you run your code on an onChange
event, if the new text value is empty.