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
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Event Handling – Adding & Removin | JavaScript Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. JavaScript Course

Lesson 10 of 55

·javascript

Event Handling – Adding & Removing Listeners

13 mins

Course progress18%

What you'll learn

Keep these ideas in mind as you work through the lesson.

3 points
  • `once:true` automatically removes the listener after the first invocation.
  • `passive:true` hints the listener will not call `preventDefault()` – improves scroll performance.
  • Event delegation (attaching one listener to a parent) reduces the number of listeners dramatically.

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);
  }
});
Make it stickPractice what you've learned1 quiz · 7 practical tests · Optional activities from JavaScript CourseBrowse activities
Previous lessonManipulating the DOM – Creation, Insertion & RemovalContinue to lesson 11Event Propagation – Capturing, Bubbling & `stopPropagation`Back to JavaScript Course curriculum