+ 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?
2 Réponses
+ 1
There's no difference
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.