+ 1

How event handlers are different from event listeners in JavaScript?

1. onclick="myFunction()"; 2. addEventListener("click", myFunction) Is there any difference among the above two ways to call myFunction when element is clicked?

25th Mar 2018, 2:22 PM
Nikhil Sharma
Nikhil Sharma - avatar
2 Réponses
+ 1
There's no difference
25th Mar 2018, 2:33 PM
Toni Isotalo
Toni Isotalo - avatar
0
Hi Nikhil as per your code there is not really a difference, but semantically -event listener is the internal code inside the browser that listens for the event you are interested in, ie mouse click, mouse move, timer tick, keyboard input etc. -event handler is the the code or function that then gets called once an event is detected. This code needs to be provided by you.
25th Mar 2018, 3:51 PM
Mike Choy
Mike Choy - avatar