HighDots Forums  

IE event order problem

Javascript JavaScript language (comp.lang.javascript)


Discuss IE event order problem in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Larax
 
Posts: n/a

Default IE event order problem - 12-04-2006 , 01:22 PM






I'm fighting with a strange problem that occures in IE, but let's start
from beggining...

I have a DIV element and SPAN element inside it, DIV has a onClick
event attached while SPAN doesn't. The problem is, when you click at
SPAN element and onClick function is called, the event.srcElement
contains SPAN element.. I have NO idea why - from logical point, it
should contain DIV element (in FF currentTarget is correctly pointing
to DIV element)

I will be grateful for any help, I ran out of ideas..


Reply With Quote
  #2  
Old   
David Golightly
 
Posts: n/a

Default Re: IE event order problem - 12-04-2006 , 03:05 PM







Larax wrote:
Quote:
I'm fighting with a strange problem that occures in IE, but let's start
from beggining...

I have a DIV element and SPAN element inside it, DIV has a onClick
event attached while SPAN doesn't. The problem is, when you click at
SPAN element and onClick function is called, the event.srcElement
contains SPAN element.. I have NO idea why - from logical point, it
should contain DIV element (in FF currentTarget is correctly pointing
to DIV element)

I will be grateful for any help, I ran out of ideas..
It's because the IE and W3C (Firefox) event models are confusingly
similar, but slightly different. This is one of their differences.
Fortunately, if you attach events using syntax like

myDiv.onclick = function(e) { alert(this); }

the "this" keyword will point to the element with the activated event
attached to it.

If you want to use the DOM Level 2 events model, see the Wikipedia page
for details on how that works:

http://en.wikipedia.org/wiki/DOM_Events



Reply With Quote
  #3  
Old   
RobG
 
Posts: n/a

Default Re: IE event order problem - 12-05-2006 , 08:51 AM




Larax wrote:
Quote:
I'm fighting with a strange problem that occures in IE, but let's start
from beggining...

I have a DIV element and SPAN element inside it, DIV has a onClick
event attached while SPAN doesn't. The problem is, when you click at
SPAN element and onClick function is called, the event.srcElement
contains SPAN element.. I have NO idea why - from logical point, it
should contain DIV element (in FF currentTarget is correctly pointing
to DIV element)
No it shouldn't, IE's event.srcElement is equivalent to the W3C's
event.target. There is no MS equivalent (AFAIK) to the W3C's
event.currentTarget.


W3C - Event.target:
<URL:
http://www.w3.org/TR/DOM-Level-2-Eve...s-Event-target
Quote:
MS - Event.srcElement:
<URL:
http://msdn.microsoft.com/workshop/a...srcelement.asp
Quote:
W3C - Event.currentTarget:
<URL:
http://www.w3.org/TR/DOM-Level-2-Eve...-currentTarget
Quote:


I will be grateful for any help, I ran out of ideas..
As suggested elsewhere, the this keyword is a better option to identify
the element that called the function.


--
Rob



Reply With Quote
  #4  
Old   
Larax
 
Posts: n/a

Default Re: IE event order problem - 12-05-2006 , 02:24 PM



Thanks for help, it seems that I have no other choice than using this
keyword.. We all love IE, doesn't we? ;P


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.