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

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

From: Ian Hickson <ian@hixie.ch>
Date: Tue, 2 Aug 2011 01:43:50 +0000 (UTC)
To: Maciej Stachowiak <mjs@apple.com>
cc: WebApps WG <public-webapps@w3.org>
Message-ID: <Pine.LNX.4.64.1108020136000.18680@ps20323.dreamhostps.com>
On Mon, 1 Aug 2011, Maciej Stachowiak wrote:
> 
>    Creates an element with the specified tag, attributes, and children.
> 
>    tagName - tag name as a string; by default it does "smart" selection 
> of SVG, HTML or MathML namespace. Authors can also use an html: svg: or 
> mathml: prefix to override these defaults.

I'd suggest just always defaulting to HTML and requiring "svg:" and 
"mathml:" prefixes for those namespaces. That makes code easier to read 
(it's obvious what's going on, and you won't accidentally use elements 
from the wrong namespace). It also makes forward-compatibility easier (we 
don't have to worry about adding new elements to the list and what that 
will do to future legacy UAs).


> (And further, you can use xmlns in attribute map to use a custom 
> namespace.)

I wouldn't bother supporting the "xmlns" attribute in this API, but I 
don't feel strongly about this.


>    attributeMap - JS object-as-dictonary or whatever dictionary type is 
> appropriate to the language, or null for no attributes

Optional attribute, too.


>    children… - veridic parameter, can include nodes, strings, or arrays. 
> Strings are converted to text nodes. Arrays are unpacked and treated as 
> lists of nodes/strings. Array support is for cases where you want to 
> have a call-site that may take a veriable-length list, with possible 
> prefix and suffix.

Also optional.


So you could also do:

   var div = Element.create('div');

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Tuesday, 2 August 2011 01:44:13 GMT

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