+ 2
Events in JavaScript
Hey, guys! So, we can add an onclick function, or other events, like this: button.onclick = ()=>{ }; button.onclick = function(){ }; button.addEventListener("click", function{ }); My question is- what are the advantages and disadvantages of event listeners and onclick functions?
7 Answers
+ 6
onclick: you can get a reference to it and you can replace the callback
with addEventListener: you can add more callback for same event and you can choose if event is triggered on bubble phase or capturing phase
+ 4
Ok? What do you mean by bubble phase or capturing phase? I'm sorry, I'm not much of a programmer. I just like to write code, so my programming basics are a bit rusty. :D
+ 4
Vasilis Karapas Dont worry, the community is here for this too đ. Anyway, see here for a good explaination https://javascript.info/bubbling-and-capturing
+ 3
Thank you! ^_^
+ 2
I use both in my codes, so I've never taken the time to think about which of the two options is more effective.
+ 2
+ 1
Vasilis Karapas đđ»