Access event.target in IE8 unobstrusive Javascript
Posted
by Mirko
on Stack Overflow
See other posts from Stack Overflow
or by Mirko
Published on 2010-04-15T01:09:25Z
Indexed on
2010/04/15
1:13 UTC
Read the original article
Hit count: 339
The following function gets the target element in a dropdown menu:
function getTarget(evt){
var targetElement = null;
//if it is a standard browser if (typeof evt.target != 'undefined'){ targetElement = evt.target; } //otherwise it is IE then adapt syntax else{ targetElement = evt.srcElement; }
//return id of
return targetElement.parentNode;
} else{ return targetElement; }
Needless to say, it works in Firefox, Chrome, Safari and Opera but it does not in IE8 (and I guess in previous versions as well). When I try to debug it with IE8 I get the error "Member not Found" on the line:
targetElement = evt.srcElement;
along with other subsequent errors, but I think this is the key line. Any help will be appreciated.
© Stack Overflow or respective owner