W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2013

Re: Convenient way to create element and set its attributes at once

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Mon, 2 Dec 2013 16:04:00 -0800
Message-ID: <CAAWBYDDDkWs_3GnMDDPcwz=ocnvnYWEDNZ=ei8Bh3qpG6r6K4Q@mail.gmail.com>
To: Marat Tanalin <mtanalin@yandex.ru>
Cc: Elliott Sprehn <esprehn@gmail.com>, "www-dom@w3.org" <www-dom@w3.org>
On Mon, Dec 2, 2013 at 3:59 PM, Marat Tanalin <mtanalin@yandex.ru> wrote:
> It would probably be more usable to have simple `Element` constructor with same arguments as `document.createElement()` method (including optional second argument containing attributes' map as I've proposed):
>      var input = new Element('input', {
>          'type' : 'email',
>          'name' : 'foo',
>          'size' : 50,
>          'placeholder' : 'e.g. example@example.com',
>          'required'    : ''
>      });

I find "new Element('h1',...)" less good to read than something like
"HTML.h1(...)".  (If you have a tagname in a string, you can always do

> It would also be consistent with already existing web-developer-friendly constructors like `new Text` and `new Comment` (implemented in Firefox 24+, Chrome 28+, and Opera 15+).

Not really.  There's a single type of Text node and Comment node.
There are many significant types of Element nodes.  This isn't a good
way to slice up the functionality.

Received on Tuesday, 3 December 2013 00:04:47 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:21 UTC