views:

3520

answers:

2

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 also we can use the 'this' kewyword to refer the object received the event.

But in explorer we don't have currentTarget property and the 'this' refers to window object!

So how can I do that?

+1  A: 

I'm assuming that you're wanting to use the 'this' context because the same handler will be dealing with multliple posible objects. In that case, see the excellent AddEvent script from the quirksmode recoding contest. (http://www.quirksmode.org/blog/archives/2005/09/addevent_recodi.html). This code has allowed me to get the very last of my javascript out of html. More importantly, it seems to work on all of the browsers that I've tested. Simple and compact.

Tom
A: 

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)

Marc-André Lafortune