Here is a function that retrieves the target element from a dropdown menu:
function getTarget(evt){
var targetElement = null;
//if it is a standard browser
if (typeof evt.target != 'undefined'){
targetElement = evt.target;
}
//otherwise for IE, use different syntax
else{
targetElement = evt.srcElement;
}
//return id of <li> element when hovering over <li> or <a>
if (targetElement.nodeName.toLowerCase() == 'li'){
return targetElement;
}
else if (targetElement.parentNode.nodeName.toLowerCase() == 'li'){
return targetElement.parentNode;
}
else{
return targetElement;
}
This function works well in Firefox, Chrome, Safari, and Opera, but encounters issues in IE8 (likely in previous versions as well). When I try to debug it with IE8, I receive an error "Member not Found" on this line:
targetElement = evt.srcElement;
followed by other subsequent errors, indicating that this is a key line causing the problem. Any assistance would be greatly appreciated.
Apologies for the formatting issue encountered earlier.
Below is the function again:
function getTarget(evt){
var targetElement = null;
//check for standard browser target
if (typeof evt.target != 'undefined'){
targetElement = evt.target;
}
//handle IE specific syntax and target retrieval
else{
targetElement = evt.srcElement;
}
//return id of <li> element when hovering over <li> or <a>
if (targetElement.nodeName.toLowerCase() == 'li'){
return targetElement;
}
else if (targetElement.parentNode.nodeName.toLowerCase() == 'li'){
return targetElement.parentNode;
}
else{
return targetElement;
}
// end getTarget