W3C home > Mailing lists > Public > public-webapi@w3.org > March 2006

Re: ACTION-70: Define the scope chain of onFoo events reference issue-1

From: Maciej Stachowiak <mjs@apple.com>
Date: Tue, 14 Mar 2006 10:22:48 -0800
Message-Id: <1A77D101-445B-4B0F-BE65-FC5881FA6C32@apple.com>
Cc: public-webapi@w3.org
To: Sergey Ilinsky <sergey@backbase.com>

On Mar 14, 2006, at 3:30 AM, Sergey Ilinsky wrote:

> -
> > <div id="a" onclick="alert('original')"
> > style="width: 200; height:
> > 200; background-color: red;"></div>
> > <br>
> > <br>
> > <div id="b"
> > onclick="document.getElementById('a').setAttribute
> > ('onclick', 'alert(\'new\')');">
> >    click here to change above listener
> > </div>
> >
> got it. but i would not think of this behaviour as of correct one  
> since script (elements/properties etc.)
> has not that much to do with markup (tags/atributes)

I'm no sure what you mean. The contents of the DOM are based on the  
markup, and many markup attribute changes set via setAttribute[NS]  
are also reflected as changes to rendering and DOM behavior. For  
example, setting the "style" attribute to "width:800; height: 800;"  
will indeed affect width and height.

This is also a behavior that all browsers have (although IE's  
setAttribute/getAttribute are broken, so you have to pass a function  
value instead of a string.

>  Well, still there is problem of event handlers processing order:
> Suppose you added several listeners to an element by calling  
> addEventListener (for FF) or attachEvent (for IE).
> element.addEventListener("click", function(event){alert(1)}, false);
> element.addEventListener("click", function(event){alert(2)}, false);
> element.addEventListener("click", function(event){alert(3)}, false);
> or
> element.attachEvent("onclick", function(event){alert(1)});
> element.attachEvent("onclick", function(event){alert(2)});
> element.attachEvent("onclick", function(event){alert(3)});
> And now you are trying to modificate the property of the element  
> corresponding to "html handler"
> element.onclick = function(event){alert(4)};
> in FF you will get 1234 after clicking on element
> and in IE yo will get 4123.
> What is the proper way (i guess FF)? Should it be defined?

In DOM Level 2 Events, the order in which event listeners trigger was  
undefined. DOM Level 3 Events will specify an ordering, which is the  
order in which they are added. I think setting the onclick JS  
property counts as adding an event listener, and my proposal  
certainly defined it as such, so the Firefox order would compl with  
the new spec.

IE does not even comply with DOM Level 2 Events so it is hard to draw  

Received on Tuesday, 14 March 2006 19:51:46 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:16:20 UTC