[whatwg] createElement convenience method

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

-----Original Message-----
From: whatwg-bounces@lists.whatwg.org
[mailto:whatwg-bounces at lists.whatwg.org] On Behalf Of Keryx Web
Sent: Saturday, October 20, 2007 3:28 PM
To: WHAT working group
Subject: [whatwg] createElement convenience method

Hello again!

I was putting together a page of exercices for my students. It's in 
Swedish and mirrored at http://gunther.ne.keryx.se/datagrund-ovningar/

This page must work when delivered from the file system so I can't use 
my beloved PHP. However, I missed one feature like crazy. Consider this:

var link_to_add  = document.createElement("a");
var link_text    = document.createTextNode(the_text.nodeValue);
link_to_add.appendChild(link_text);

If PHP:s convenience additions to the W3C DOM were made standard (and 
implemented in browsers) it could have been:

var link_to_add  = document.createElement("a",the_text.nodeValue);

What I propose is this second text-parameter to the createElement method 
(or a third for createElementNS).

See http://se.php.net/manual/en/function.dom-domdocument-createelement.php
http://se.php.net/manual/en/function.dom-domdocument-createelementns.php

Has the standardization of this functionality ever been discussed? If 
so, can someone point me to that discussion?


Lars Gunther

P.S In PHP I can also get the text between start- and end-tags of an 
element with

element.nodeValue

instead of

element.firstChild.nodeValue

Even if I've yet to see any bad repercussions from this convenient 
shortcut, I could imagine it is a bit more shaky...

Received on Sunday, 21 October 2007 03:43:48 UTC