da********@yahoo.com (Dan Diebolt) writes:
I need some script that change "foo" to "bar" anywhere "foo" occurs on
the page once the page is loaded. Any idea how?
Best guess is to run through the DOM tree:
---
function crawlDOM(node,fnode,ftext) {
switch (node.nodeType) {
case 1: // normal node
for(var i = 0;i<node.childNodes.length; i++) {
crawlDOM(node.childNodes[i],fnode,ftext);
}
fnode(node);
break;
case 3: // text node
ftext(node);
break;
}
}
---
Then you can do:
---
crawlDOM(document.body,
function (){},
function (tnode) {
tnode.nodeValue = tnode.nodeValue.replace(/foo/g,"bar");
});
---
You just have to pray that the document tree really is a tree :)
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'