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
keyword to refer to the object processing the event.
But in Internet Explorer we don't have currentTarget
property and the this
refers to window object!
So how can I do that?
The currentTarget read-only property of the Event interface identifies the current target for the event, as the event traverses the DOM. It always refers to the element to which the event handler has been attached, as opposed to Event.
currentTarget tells us on which element the event was attached or the element whose eventListener triggered the event. event. target tells where the event started.
You're likely getting this error because you're trying to get a name attribute on elements that don't have a name attribute. For example; input, textarea, and form elements are naturally able to get a name attribute. But elements like div, span doesn't.
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.
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 :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With