0

I am learning JavaScript I have a question while I studied to Event.

As I know we have two ways to handle an event, Event Handler and Event Listener.

I can only have one event handler for a specific event type, but I can add multiple event listeners for it.

It seems like event listener is better than handler, and why or when do we need the Event Handler ?

EnergyBoy
  • 547
  • 1
  • 5
  • 18
  • 3
    From MDN _Note: Event handlers are sometimes called event listeners — they are pretty much interchangeable for our purposes, although strictly speaking, they work together. The listener listens out for the event happening, and the handler is the code that is run in response to it happening._ – brk May 06 '22 at 05:26
  • two words ... legacy code - browsers sill support `eval`, browsers still support synchronous XMLHttpRequest ... half the world wide web would fail if these legacy methods disappeared from modern browsers - some coders still use such legacy methods today because they are taught that way in low rent universities – Bravo May 06 '22 at 05:32
  • Does this answer your question? [addEventListener vs onclick](https://stackoverflow.com/questions/6348494/addeventlistener-vs-onclick) – Yogi May 06 '22 at 05:44
  • @brk sound like the listener is a monitor, and handler is a worker – EnergyBoy May 06 '22 at 06:31
  • Event handlers are the original way, event listeners were added later to be more general. – Barmar May 06 '22 at 06:34

0 Answers0