W3C home > Mailing lists > Public > public-webapps@w3.org > July to September 2011

Re: Element.create(): a proposal for more convenient element creation

From: Anne van Kesteren <annevk@opera.com>
Date: Wed, 03 Aug 2011 17:51:28 +0200
To: "Glenn Maynard" <glenn@zewt.org>
Cc: "Tab Atkins Jr." <jackalmage@gmail.com>, "Aryeh Gregor" <ayg@aryeh.name>, "Maciej Stachowiak" <mjs@apple.com>, "WebApps WG" <public-webapps@w3.org>
Message-ID: <op.vznab2lt64w2qv@annevk-macbookpro.local>
On Wed, 03 Aug 2011 17:46:50 +0200, Glenn Maynard <glenn@zewt.org> wrote:
> What's the difference?

ele.setAttribute(x, val) works on any element. ele[x] = val does not. They  
also behave differently for a large number of cases and the latter often  
takes values of a type other than DOMString.


> I'd expect this:
>
> a = Element.create("a", {href: "http://link", onclick: function(e) { },
> custom: "value" }, "link");
>
> to be essentially equivalent to
>
> a = document.createElement("a");
> a.appendChild(document.createTextNode("link"));
> attrs = {href: "http://link", onclick: function(e) { }, custom: "value"  
> };
> for(key in attrs) a[key] = attrs[key];

Would you expect to write contenteditable as contenteditable or as  
contentEditable? Also, would you expect custom to end up as a content  
attribute on that <link> element? Because it will not with this code.


-- 
Anne van Kesteren
http://annevankesteren.nl/
Received on Wednesday, 3 August 2011 15:52:02 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:46 GMT