1

The question is whether I can call a function on event of clicking close button in search box. What I'm using is <input type='search'>

While typing, close button appears clicking on which I want to call a particular function. Is it possible? I tried to Google it but couldn't get much out of it. Can anyone help?

Guy in the chair
  • 1,045
  • 1
  • 13
  • 42
  • it is not clear what do you want to achieve. Which part is already done? give the fiddle please – Mr.Cocococo Jun 13 '14 at 04:13
  • I do not know whether this thing is possible or not, so a question. When you have `` in your code, it shows clear button at the end of you search field when you type. If you click on that clear button, that clears all characters from search box. I want to trigger an event on that click, to close my another div. – Guy in the chair Jun 13 '14 at 04:15
  • Yes it is possible... you might want to look at the jQuery `.on()` function. – Ballbin Jun 13 '14 at 04:16
  • I'm well aware about the jQuery, but that clear button is integrated in HTML5 search box, I do not on which part I should use `.on` function. – Guy in the chair Jun 13 '14 at 04:17

2 Answers2

2

You can use jQuery .on('search', function() { ... }) to handle this event. Here is a fiddle example: http://jsfiddle.net/7EynL/

See this question for additional details.

Community
  • 1
  • 1
jandersen
  • 3,551
  • 22
  • 23
2

Use 'search' event

$('input[type="search"]').on('search', function(event) {
});
Shaunak D
  • 20,588
  • 10
  • 46
  • 79