Reputation: 383
I'm trying to debug a scenario where hitting Enter on a submit button eventually causes a 'click' event to be fired on that button. I can only assume that the click event was fired programmatically. Having the click event fire is apparently the correct behavior in the application, but I need to track down its origin because I'm having some cross-browser issues with it.
I am using jQuery and ExtJS, and the key press handlers are all being routed first through jQuery, then through Ext, then to our code. The button is an Ext object. I have stepped through all the key handlers, and I haven't run across any instances of fireEvent('click') or anything to explain where the click event is coming from.
The events I'm aware of are firing in this order:
The click event still fires if I suppress the handling of keydown and keypress.
The call stack on the click handler doesn't tell me where the event came from, so I've resorted to searching through the code base and putting breakpoints on instances of the following:
Is there anything else I can search for? Are there better strategies for debugging the interplay of Javascript events?
Upvotes: 1
Views: 1551
Reputation: 13505
This isn't strange behaviour by any means. It's default behaviour on all button elements, no matter what browser. AFAIK, if you hit enter on a button it will not fire a keyup/keydown event because they don't exist on that DOM element.
Firing a click event in this instance is completely normal.
I've setup an example to demonstrate this...
When the page loads, the button will focus. If you press enter, the keyCode that is returned is 0. It fires a click event by default.
Upvotes: 1
Reputation: 51072
jQuery can fire a click event by using the method click()
. Note the empty parentheses.
Upvotes: 1