Skip to content
Justice Tech School

Event Delegation

Attach one handler to a parent and give a selector so it also works for elements added later. It saves memory too.

Example
$('#list').on('click', 'li', function () {
  $(this).toggleClass('done');
});

Exercise

Parent handler selector.

$('#list').on('click', '', fn)

Quiz Test

Why delegate?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.