Fix onbeforechange callback receiving the wrong element