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

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 UTC