W3C home > Mailing lists > Public > whatwg@whatwg.org > October 2007

[whatwg] createElement convenience method

From: Michaeljohn Clement <mj@mjclement.com>
Date: Mon, 22 Oct 2007 17:03:52 -0700
Message-ID: <471D3A68.9060606@mjclement.com>
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
Received on Monday, 22 October 2007 17:03:52 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:08:37 UTC