fix issue where event listener was being attached to an element that hadn't been loaded yet