attach event handler for elements