Replaced event.toElement with event.target for cross-browser compatibility