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 14:09:33 -0800
Message-Id: <BE63118D-5086-4D3E-A3C0-5255796526B1@apple.com>
Cc: "\"Web APIs WG (public)\"" <public-webapi@w3.org>
To: Jim Ley <jim@jibbering.com>

On Mar 14, 2006, at 12:16 PM, Jim Ley wrote:

> "Maciej Stachowiak" <mjs@apple.com>
>>> Inconsistency is very annoying for the author.
>> 1) Safari, Firefox, Opera and IE all have live event listener   
>> attributes.
> IE does not, it only has live properties ie onclick=function() {}  
> works but setAttribute("onclick","alert(1)");  does not result in  
> an alert if you click it.  (you can pass a function as the 2nd  
> parameter to setAttribute, but that would be non-conformant, and  
> doesn't work in any other UA)

The fact that IE's setAttribute is buggy doesn't mean the attribute  
isn't live. It is. And in fact, passing a function value will be  
reflected in the DOM attribute's text value when you serialize the  

> 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.

They don't "re-execute the attribute" but they do treat changes to  
the attribute as updating the event listener. The conceptual model  
doesn't involve executing the attribute at all, it is made into a  

The DOM has other areas where there is both an element attribute and  
a corresponding DOM attribute, and both have an effect when changed  
but changing the DOM property doesn't necessarily affect the attribute.

In any case, this doesn't seem like a reason to reverse the behavior  
of setAttribute.

> In firefox 1.5:
>       document.body.onclick=function() { alert(2) }
>       document.body.setAttribute('onclick','alert(3)');
> results in both 2 and 3 being alerted.
> So I don't really agree that there is great consistency in  
> setAttribute and event properties, none of the 3 I've tested here  
> interopate at all - given that I would prefer to say only the one  
> that is universal - the property, is the one that should be used  
> and setAttribute should not, as that provides maximum compatibilty.

I agree that authors shouldn't set event listeners via setAttribute.  
But I don't think the spec should require setAttribute to have no  
effect on event listeners, since it does have an effect in current  

Received on Tuesday, 14 March 2006 22:09:59 UTC

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