Reputation: 1382
On accident, I did something I think might be wrong.
I added two event handlers to the same element/event.
What is the default behavior, or is there one?
That is if you add two click events to the same element. Will they both be fired and in what order.
Upvotes: 0
Views: 30
Reputation: 963
Here is what the spec says:
Although all EventListeners on the EventTarget are guaranteed to be triggered by any event which is received by that EventTarget, no specification is made as to the order in which they will receive the event with regards to the other EventListeners on the EventTarget.
http://www.w3.org/TR/DOM-Level-2-Events/events.html
So they will both be fired but the order is not guaranteed.
Upvotes: 1
Reputation: 722
They will both fired if you bind event by addEventListener or attachEvent. The order is decided by binding order,for example(the code is write in jquery):
$('#id').bind('click',function(){
alert(1);
}).bind('click',function(){
alert(2)
});
when you click the element ,you will see alert '1' first, then is '2';
Upvotes: 1