Bugfix: fixes Issue 152

Based on a comment by @drgomesp, this commit fixes the bug with onbeforechange callback receiving the wrong DOM element.