Re: [whatwg] createElement convenience method

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 UTC