W3C home > Mailing lists > Public > public-html@w3.org > October 2007

Re: [whatwg] createElement convenience method

From: Thomas Broyer <t.broyer@gmail.com>
Date: Mon, 22 Oct 2007 09:04:51 +0200
Message-ID: <a9699fd20710220004o59b20241r89ba030a6e9807d@mail.gmail.com>
To: public-html@w3.org
2007/10/21, Keryx Web:
> Křištof Želechovski skrev:
> > Convenience methods such as the one proposed here should not make it to the
> > standard for the sake of clarity and compatibility; the programmer can reuse
> > an existing wrapper function instead:
> > var link_to_add = createLink(link_text);
> > This approach is safer and saner.
> > Best regards,
> > Chris
>
> I beg to differ. Native functions speed things up. My suggestion is both
> sane and safe as it is.
>
> This suggestion falls into the exact same category as
> getElementsByClassName.

How would you test that it is available?

<script>if ("getElementsByClassName" in document) { ... }</script>
or
<script>if (document.getElementsByClassName) { ... }</script>
work, but how would you test that createElement and/or createElementNS
can take an additional argument?

createElementWithTextContent could work, but then you'd also want a
createAttributeWithValue.

I doubt though there would be a huge advantage over doing:
    var link_to_add = document.createElement("a");
    link_to_add.textContent = the_text.nodeValue;

-- 
Thomas Broyer
Received on Monday, 22 October 2007 07:05:00 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 7 December 2009 10:40:04 GMT