DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Event Target

05.04.2009
| 4147 views |
  • submit to reddit
        Gets the target element from an event, cross broser

<b>Usage:</b>
getEventTarget( evt as Event );

<b>Code:</b>
function getEventTarget(evt) {
	var elem;
	if (evt.target) {
		elem = (evt.target.nodeType == 3) ? evt.target.parentNode : evt.target;
	} else {
		elem = evt.srcElement;
	}
	return elem;
}