본문으로 건너뛰기
Skillpedia
웹사이트 및 UI (프런트엔드)75k · #2837

event-delegation

하는 일

이 스킬은 목록 항목이나 표 행에 많은 이벤트 리스너를 붙이는 코드를 검토합니다. 목록과 동적 페이지를 만드는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓긴 목록의 모든 항목에 같은 클릭 핸들러를 붙일 때.
  • ✓나중에 추가된 목록 항목이 클릭에 반응하지 않을 때.
  • ✓리스너가 많은 페이지가 메모리를 너무 많이 쓸 때.

스킬 링크

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/event-delegation/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/event-delegation/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“이 목록의 클릭 핸들러를 간단하게 바꿔서, 새로 추가되는 항목도 동작하게 해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트는 여러 자식에 붙은 같은 핸들러를 찾아 그 부모에 리스너 하나를 두라고 제안합니다. closest를 사용해 클릭된 항목을 알아냅니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Use event delegation for dynamic content

Adding hundreds of individual event listeners for list items or table rows consumes significant memory and creates performance overhead. Dynamic content (items loaded via AJAX or rendered after user actions) won't have event listeners unless you re-attach them after each update — event delegation solves both problems at once.

Quick Reference

  • Attach one listener to a parent instead of many to individual children
  • Use event.target.closest() to identify the intended target element
  • Event delegation automatically works for elements added dynamically
  • Clean up listeners on the parent when the container is removed

Check

Find any code in this file that attaches the same event handler to multiple elements in a loop. Suggest event delegation as an alternative.

Fix

Refactor these per-element event listeners to use event delegation on the common parent container.

Explain

Explain event delegation, how event bubbling enables it, and when to use closest() vs target.

Code Review

Review scripts, client components, and browser execution paths related to Use event delegation for dynamic content. Flag exact imports, event handlers, runtime side effects, or blocking operations that violate the rule, and state how the change should be verified in the browser.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/javascript/event-delegation

자주 묻는 질문

이벤트 위임이란 무엇인가요?

각 자식에 리스너를 두지 않고 공유 부모 요소에서 듣다가, 어느 자식이 이벤트를 발생시켰는지 확인하는 방식입니다.

왜 새 콘텐츠에 도움이 되나요?

부모 리스너는 페이지 로드 후에 추가된 항목을 포함해 모든 자식의 이벤트를 잡습니다.

closest는 무엇에 쓰이나요?

클릭이 그 안의 다른 요소에서 일어나도 의도한 요소를 찾기 위해 closest를 씁니다.

상세 정보

작성자의 원본 설명

Use when reviewing scripts, client components, bundles, or runtime behavior related to Use event delegation for dynamic content. Inspect both source code and the browser execution path so fixes target the real bottleneck or bug.

repo: thedaviddias/Front-End-Checklist

인기도

GitHub 스타
75k
순위
#2837
라이선스
MIT
업데이트
2026. 10. 31.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬