Is there a way to take the current target of an event with IE 7 or 8?
With other browser (firefox, opera, chrome etc.) we can use
event.currentTarget or
This function creates currentTarget in case it is IE, so you no longer need to patch your code!
function eventListener(e,t,f) {
if(e.addEventListener)
e.addEventListener(t,f);
else
e.attachEvent('on' + t,
function(a){
a.currentTarget = e;
f(a);
});
}
Regular JS(will not work on IE below 9):
function myfunction(e) {
alert(e.currentTarget.id);
}
e = document.getElementById('id');
e.AddEventListener(e,'mouseover',myfunction);
With this function(will work on IE below 9):
function myfunction(e) {
alert(e.currentTarget.id);
}
e = document.getElementById('id');
eventListener(e,'mouseover',myfunction);