At its core my issue is the following:
$('input').click (e) ->
# do some things conditionally, depending on the event origin
false
$('a').click ->
$('input').click()
So the issue is, how can I tell who started the event.
Please note that in both of the cases (either clicking the input or the link e.target is the same).
Update: I posted the code above here: http://jsfiddle.net/w7faW/1/
Thanks.
You can pass parameters when triggering events programmatically using the
triggerfunction:There i’m passing an optional argument
targetwhich defaults toe.target, and when clicking on the link, the link itself is passed as that parameter. Then you can use that parameter to check which was the triggering element. You can check the different outputs in this jsfiddle.However, given this simple example, i must say that this solution is probably a bit confusing, i’d prefer just using the same function as a click handler for both elements (jsfiddle):
Or, if you need to do something different for each element and then something in common for both, you can just use another function for that common behavior: