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: Jonas Sicking <jonas@sicking.cc>
Date: Wed, 15 Mar 2006 05:51:52 -0800
Message-ID: <44181BF8.8050307@sicking.cc>
To: Jim Ley <jim@jibbering.com>
Cc: "Web APIs WG (public)" <public-webapi@w3.org>

Jim Ley wrote:
> There are further differences, in Opera 8.5/9 and Mozilla:
> 
> alert(document.body.getAttribute('onclick'));
> document.body.onclick=function() { chicken() }
> alert(document.body.getAttribute('onclick'));
> 
> the getAttribute doesn't reflect the change to the onclick property - 
> but does result in the function being called not the attribute, so the 
> UA's are not simply re-executing the attribute at each point in time, so 
> it's not clear why changing the attribute should have an effect.

What's happening is that the js property and the DOM attribute is only 
synced one way. Changes to the attribute affects the property, but not 
the other way around.

This isn't very good and ideally I would like the spec to say that the 
synchronization happens both ways.

The only problem with syncing both ways that I can think of is that it 
requires that the implementation has a reliable .toSource() 
implementation. I'm not sure if that is a too harsh requirement.

> In firefox 1.5:
>       document.body.onclick=function() { alert(2) }
>       document.body.setAttribute('onclick','alert(3)');
> results in both 2 and 3 being alerted.

I believe this is unique to the body and html elements and due to the 
fact that for these elements the listener is registered on the window. 
However I consider this a bug in the implementation and not something we 
should model the spec after since I doubt many sites rely on it.

/ Jonas
Received on Wednesday, 15 March 2006 13:51:53 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 8 January 2008 14:18:53 GMT