create event delegation function