Updated event handling to parse the element object