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

"Tab Atkins Jr." <[email protected]>
Newsgroups gmane.comp.web.dom.general
Message-ID <CAAWBYDDDkWs_3GnMDDPcwz=ocnvnYWEDNZ=ei8Bh3qpG6r6K4Q@mail.gmail.com>
On Mon, Dec 2, 2013 at 3:59 PM, Marat Tanalin <[email protected]> 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. [email protected]',
>          '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
HTML[tag](...).)

> 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.

~TJ
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.