Attaching event handlers to dynamically created JavaScript