Change to check on createEvent instead of attachEvent, since the function uses createEvent