Most efficient way to create and nest divs with appendChild using *plain* javascript (no libraries)

Posted by Matrym on Stack Overflow See other posts from Stack Overflow or by Matrym
Published on 2010-04-19T21:21:53Z Indexed on 2010/04/19 21:33 UTC
Read the original article Hit count: 337

Filed under:
|
|

Is there a more efficient way to write the following appendChild / nesting code?

var sasDom, sasDomHider;
var d = document;
var docBody = d.getElementsByTagName("body")[0];
var newNode = d.createElement('span');
var secondNode = d.createElement('span');

// Hider dom
newNode.setAttribute("id", "sasHider");
docBody.appendChild(newNode);
sasDomHider = d.getElementById("sasHider");

// Copyier dom
secondNode.setAttribute("id", "sasText");
sasDomHider.appendChild(secondNode);
sasDom = d.getElementById("sasText");

Thanks in advance for your time :)

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about appendchild