+ 2

how can i add multiple events using add event listener?? I'm confused

js

19th Sep 2018, 3:14 PM
Bisnu😎
5 ответов
+ 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; }
19th Sep 2018, 4:06 PM
Kirk Schafer
Kirk Schafer - avatar
+ 1
element.addEventListener(event, function); element.addEventListener(event2, function2);
19th Sep 2018, 3:17 PM
N00B
0
Thnx bt will the 2nd one override another during execution??
19th Sep 2018, 3:21 PM
Bisnu😎
0
Bishnu If you don't use the same event twice it shouldn't override it.
19th Sep 2018, 3:35 PM
N00B
0
Bishnu events won't be overridden, but you can remove them if you don't want it
20th Sep 2018, 9:49 AM
Flandre Scarlet
Flandre Scarlet - avatar