+ 2
how can i add multiple events using add event listener?? I'm confused
js
5 Réponses
+ 3
Note, you can hook the same event twice; javascript will call both:
document.addEventListener('click', fn1, false);
document.addEventListener('click', fn2, false);
function fn1(event){
document.getElementsByTagName("body")[0].innerHTML += "1:" + event;
// stop additional handlers on same element + bubbling up the tree
// event.stopImmediatePropagation();
}
function fn2(event){
document.getElementsByTagName("body")[0].innerHTML += "2:" + event;
}
+ 1
element.addEventListener(event, function);
element.addEventListener(event2, function2);
0
Thnx bt will the 2nd one override another during execution??
0
Bishnu If you don't use the same event twice it shouldn't override it.
0
Bishnu events won't be overridden, but you can remove them if you don't want it