[whatwg] createElement convenience method

Michaeljohn Clement mj at mjclement.com
Mon Oct 22 17:03:52 PDT 2007


Keryx Web wrote:
> var link_to_add  = document.createElement("a");
> var link_text    = document.createTextNode(the_text.nodeValue);
> link_to_add.appendChild(link_text);

Or you can write:

var link_to_add = document.createElement("a").appendChild(document.createTextNode("xyz"))

And if you find yourself doing this more than once or twice, you 
can always use a wrapper function.

-Michaeljohn



More information about the whatwg mailing list