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

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

From: Dominic Cooney <dominicc@google.com>
Date: Sun, 7 Aug 2011 01:05:43 +0900
Message-ID: <CAHnmYQ_6huYV+aF5dmnsXRUg7=BLys2T5WbWYOejdH82ouNEYA@mail.gmail.com>
To: WebApps WG <public-webapps@w3.org>, Jonas Sicking <jonas@sicking.cc>, Maciej Stachowiak <mjs@apple.com>
Cc: Garrett Smith <dhtmlkitchen@gmail.com>, "Tab Atkins Jr." <jackalmage@gmail.com>, Anne van Kesteren <annevk@opera.com>, Glenn Maynard <glenn@zewt.org>, Aryeh Gregor <ayg@aryeh.name>
Element.create looks neat. Three thoughts:

First, I think Element.create *and* constructors like new
HTMLDivElement(attributes, children) are both useful. Element.create is good
when you have a tag name in hand, are creating unknown elements, or are
creating elements that don’t have a specific constructor (ins/del.)

New is good when you’re creating an element “statically.” It’s succinct, and
if you misspell the name you get an exception instead of an unknown element,
for example:

Element.create('vdieo', {src: '…'}) → no error, HTMLUnknownElement that
behaves nothing like <video>

new HTMLVdieoElement({src: '…'}) → ReferenceError, stack trace points me to
the faulty line of code.

When the element being created is “static” I think constructors are more
readable, too:

var b = Element.create('button', {}, [
  Element.create('img', {src: 'http://'}),
  document.createTextNode('Click me!')

compared to:

var b = new HTMLButtonElement({}, [
  new Image('http://'),
  new TextNode('Click me!')

Let me briefly reiterate that I think we want *both* Element.create and
constructors; they have complementary uses.


Second, re: setAttribute vs setting properties, there might be types other
than functions we want to not treat as strings; for example if a UA
implements CSSOM it might be nice to be able to set a style without having
to serialize and reparse the CSSStyleDeclaration.

Can we spec whether something in the attributes hash is set via setAttribute
or via setting a property based on the IDL for that element?

Alternatively we could provide a syntax, eg '@class': 'foo' to
setAttribute('class', 'foo') and className: 'foo' to set elem.className =


Third, is the order of attributes significant for XML namespace
declarations? eg does this:

<x xmlns:foo="…" foo:bar="…" />

mean the same thing as

<x foo:bar="…" xmlns:foo="…" />

? If not, including namespaces in the attribute dictionary is fraught,
because the iteration order of properties is undefined.


On Fri, Aug 5, 2011 at 3:22 PM, Garrett Smith <dhtmlkitchen@gmail.com>wrote:

> On 8/4/11, Garrett Smith <dhtmlkitchen@gmail.com> wrote:
> [...]
> ser-generated function function.
> >
> > The scope of handler attributes is explained in HTML 5, though
> > incompletely:
> >
> http://dev.w3.org/html5/spec/Overview.html#event-handler-content-attributes
> > That's incomplete.
> >
> Correction: It is complete, I just misread it.
> --
> Garrett
Received on Saturday, 6 August 2011 16:06:09 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:26:34 UTC