Internet Explorer and JavaScript event currentTarget

Solution 1:

You can do something like

target = (event.currentTarget) ? event.currentTarget : event.srcElement;

Although as @Marc mentioned you can use a JQuery framework that normalizes the event for you.

Solution 2:

I had similar problem. I solved it using keyword this as stated in an article on brainjar.com

To get the equivalent of the currentTarget property in IE, use the this keyword as an argument when setting the event handler in a tag.

...

function myHandler(event, link) { ... }

On the same page you can find the following table :

enter image description here

Solution 3:

The short answer is: use jQuery.

Although event.currentTarget is not accessible on IE, jQuery will normalize the event for you so your code would also work on IE (as stated here)

Note that using event.srcElement, as suggested in other answers is not equivalent, since srcElement corresponds to the target, not to currentTarget, as explained at the end of this page.

Solution 4:

with this function you can pass the object when adding and get it in the listener. the problem about this is that you have an anonymous function as eventlistener and in actionscript you cannot remove an anonymous listener. dunno bout js.

addEvent:function(object,type,listener,param)
    {
    if(object.addEventListener)
      object.addEventListener(type, function(e){ listener(object, e, param);}, false );
    else
    if(object.attachEvent)
      object.attachEvent('on'+type, function(e){ e = getEvent(e); listener(object, e, param);});
    },

getEvent:function(e)
        {
    if(!e) e = window.event; // || event
    if(e.srcElement) e.target = e.srcElement;
    return e;
    },

removeEvent:function(object,type,listener)
    {
    if(object.removeEventListener)
    object.removeEventListener(type, listener, false);
    else
    object.detachEvent('on'+type, listener);
    }

var div = document.getElementById('noobsafediv');
var div2 = document.getElementById('noobsafediv2');
addEvent(div,'mouseover',mouseover,['astring',111,div2]);


function mouseover(object,e,param)
 {
 console.log(object,e,param);
 }

its my framework and i call it jNoob.