How does the "this" keyword behave in event handlers?

  • It refers to the element that triggered the event.
  • It refers to the document object.
  • It always refers to the window object.
  • It throws an error since "this" cannot be used in event handlers.
In event handlers, such as those in JavaScript for the web, the "this" keyword typically refers to the DOM element that triggered the event. This behavior allows developers to access and manipulate the specific element that triggered the event, making it a powerful feature in front-end web development.
Add your answer
Loading...