Attach events to a parent to handle dynamically added children:
// Won't work for dynamic elements:
$('li').on('click', fn);
// Works for any li added later:
$('ul').on('click', 'li', function() {
$(this).toggleClass('done');
});Delegation is more efficient when you have many elements.