View Full Version : DomHelper

19 Oct 2006, 11:15 AM
using DomHelper to create a table.

do I have to create the tbody and append tr nodes to that?

var rs = getEl('recordset');
var table = dh.append(rs, {tag: 'table', cls: 'foo'});
var tbody = dh.append(table, {tag: 'tbody'});

does DomHelper::append() append the node immediately to the doc? isn't that inefficient? when creating DOMNodes, are we not supposed to first create a container element, append the children to it, then append the container to the doc, since the teh document object must recalculate everything when a node is appended to it?


var container = getEl('container');
var ul = document.createElement('ul');
for (var i=0; i < 10; i++) {
var li = document.createElement('li');

// finish by appending newly create ul to container

19 Oct 2006, 11:47 AM
For the table problem:


Yes it adds the nodes immediately that way.

If you are building something big and don't want to append it all at once you can create a node to use as a buffer with dom and then append to it. Personally I wouldn't worry about it. If you looked at the benchmark, it created 3000 elements in about 300 milliseconds appending them all at once. If you change it to not all at once you will see the difference in not that much, approx 50 milliseconds for 3000 elements.