Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. JavaScript Course

Lesson 10 of 55 · javascript

Event Handling – Adding & Removing Listeners

Duration: 13 mins

Event listeners are added with addEventListener.

button.addEventListener('click', handleClick, { once:true, passive:true });
  • type – event name (click, keydown).
  • listener – function or object with a handleEvent method.
  • options – capture, once, passive.

Removing:

button.removeEventListener('click', handleClick);

Example: Delegated click handling

document.body.addEventListener('click', e => {
  if (e.target.matches('a[data-action]')) {
    console.log('Link clicked:', e.target.dataset.action);
  }
});
Previous: Manipulating the DOM – Creation, Insertion & RemovalNext: Event Propagation – Capturing, Bubbling & `stopPropagation`