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

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

From: Charles Pritchard <chuck@jumis.com>
Date: Tue, 02 Aug 2011 11:12:59 -0700
Message-ID: <4E383E2B.5050806@jumis.com>
To: Aryeh Gregor <ayg@aryeh.name>
CC: Maciej Stachowiak <mjs@apple.com>, WebApps WG <public-webapps@w3.org>
On 8/2/2011 9:48 AM, Aryeh Gregor wrote:
> On Mon, Aug 1, 2011 at 9:33 PM, Maciej Stachowiak<mjs@apple.com>  wrote:
>> In an IRC discussion with Ian Hickson and Tab Atkins, we can up with the
>> following idea for convenient element creation:
>> Element.create(tagName, attributeMap, children…)
>>     Creates an element with the specified tag, attributes, and children.
> How does this compare to popular JS helper libraries like jQuery?  It
> would be useful to know what convenience APIs authors are using now
> before introducing our own.

Here are three common helper libraries.

var myAnchor = new Element('a', { href: 'http://mootools.net' });
// notes: namespacing requires escaping the colon \:
// moo enables: new Element('a.className') as a shorthand.
myAnchor.set({ key: val});
// styles and events are keywords.

var li = dojo.create("li", { innerHTML: "Six"});
// notes: dojo allows a third and fourth param to specify parent / child 
nodes and positioning.
dojo.attr(li,{key: val});

var myAnchor = $('<a href="http://api.jquery.com">');
myAnchor.attr({key: val});
// attr also acts as a getter, when a string is passed, and a computed 
setter, when a function is used for a value.
Received on Tuesday, 2 August 2011 18:13:34 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:13:23 UTC