J
Joe Kelsey
I want to create dynamic content and use replaceChild to switch out
different subtrees. I start with a span placeholder:
<span id="replaceMe"></span>
Then I use document.getElementById ("replaceMe") to find the element
to replace. I create a subtree using standard DOM:
var table = document.createElement ("table");
table.insertRow ();
....
var replace = document.getElementById ("replaceMe");
replace.parent.replaceChild (table, replace);
If I intend to replace the node several times, should I instead use:
var span = document.createElement ("span");
span.appendChild (table);
var replace = document.getElementById ("replaceMe");
span.id = replace.id;
replace.parent.replaceChild (span, replace);
Does anyone have alternative ideas for replacing portions of documents
that do not resort to using innerHTML or other abominations?
/Joe
different subtrees. I start with a span placeholder:
<span id="replaceMe"></span>
Then I use document.getElementById ("replaceMe") to find the element
to replace. I create a subtree using standard DOM:
var table = document.createElement ("table");
table.insertRow ();
....
var replace = document.getElementById ("replaceMe");
replace.parent.replaceChild (table, replace);
If I intend to replace the node several times, should I instead use:
var span = document.createElement ("span");
span.appendChild (table);
var replace = document.getElementById ("replaceMe");
span.id = replace.id;
replace.parent.replaceChild (span, replace);
Does anyone have alternative ideas for replacing portions of documents
that do not resort to using innerHTML or other abominations?
/Joe