Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - Find out what triggered the event [duplicate]

Possible Duplicate:
Getting the ID of the element that fired an event using jQuery

How do we find out what triggered an event?

I want to find out if a search input was triggered using the enter key or by clicking on a button.

like image 666
Hussein Avatar asked Feb 08 '11 06:02

Hussein


1 Answers

I assume your binding to the search input using jQuery handlers as such. So just pass the event type along. For more information, pass the entire event object along:

$("input.Search").click(function(event) {
    doMySearch(this, "click");
}).keyup(function(event) {
    doMySearch(this, "keyup");
}); 

function doMySearch(element, eventtype) {
   ...
}
like image 190
Raynos Avatar answered Oct 27 '22 10:10

Raynos