The following function gets the target element in a dropdown menu:
function getTarget(evt){
var targetElement = null;
//if it is a standard browser
if (
The problem is that in IE, the event object is not sent as an argument of the handler, it is just a global property (window.event
):
function getTarget(evt){
evt = evt || window.event; // get window.event if argument is falsy (in IE)
// get srcElement if target is falsy (IE)
var targetElement = evt.target || evt.srcElement;
//return id of - element when hovering over
- or
if (targetElement.nodeName.toLowerCase() == 'li'){
return targetElement;
}
else if (targetElement.parentNode.nodeName.toLowerCase() == 'li'){
return targetElement.parentNode;
}
else{
return targetElement;
}