Which method is used to attach an event listener to an element in JavaScript?

  • addListener()
  • addEventListener()
  • attachEvent()
  • addEventHandler()
In JavaScript, the correct method to attach an event listener to an element is addEventListener(). This method allows you to specify the event type to listen for and the function to execute when the event occurs. It is the modern and recommended way to handle events in JavaScript.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *