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 10:26:28 -0800
Message-ID: <CAAWBYDDCPFWc5kns_+8FJh7ea0uM86ZxaVB9Q8NYsArgji1a6Q@mail.gmail.com>
To: Elliott Sprehn <esprehn@gmail.com>
Cc: "Marat Tanalin | tanalin.com" <mtanalin@yandex.ru>, "www-dom@w3.org" <www-dom@w3.org>
On Sun, Dec 1, 2013 at 8:05 PM, Elliott Sprehn <esprehn@gmail.com> wrote:
> I believe we should just solve this with the constructor syntax:
> new HTMLDivElement({
>   id: "foo"
> });
> and
> new HTMLHeadingElement("h1", {
>   id: "foo"
> });


Note that when this has come up previously, there's been need to set
both attributes and properties.  It's confusing, unfortunately, but
necessary - for example, if you want to set an onclick handler from
the constructor with a function, you have to assign the onclick
property; if you have a string containing code, you have to assign the
onclick attribute.  Some controls you want to be able to set on an
element are only accessible via a property.

Note as well that when CSS sprouted a namespace object on window, one
of the planned purposes was to host short-named constructors for the
various Value API thing we'll need, like "new CSS.px(5)" rather than
"new CSSPixelComponentValue(5)".  It would be useful for HTML to do
the same, so you could call "new HTML.div(...)" instead of "new
HTMLDivElement(...)".  It would also let us establish a one-to-one
constructor to tagname correspondence, so "HTML.h1()" works instead of

Received on Monday, 2 December 2013 18:27:15 UTC

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