Generalize event delegation to 'on' function