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.getEle mentById ("replaceMe" ) to find the element
to replace. I create a subtree using standard DOM:
var table = document.create Element ("table");
table.insertRow ();
....
var replace = document.getEle mentById ("replaceMe" );
replace.parent. replaceChild (table, replace);
If I intend to replace the node several times, should I instead use:
var span = document.create Element ("span");
span.appendChil d (table);
var replace = document.getEle mentById ("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.getEle mentById ("replaceMe" ) to find the element
to replace. I create a subtree using standard DOM:
var table = document.create Element ("table");
table.insertRow ();
....
var replace = document.getEle mentById ("replaceMe" );
replace.parent. replaceChild (table, replace);
If I intend to replace the node several times, should I instead use:
var span = document.create Element ("span");
span.appendChil d (table);
var replace = document.getEle mentById ("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
Comment