Add an event handler to an element using code