da********@yaho o.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,f node,ftext) {
switch (node.nodeType) {
case 1: // normal node
for(var i = 0;i<node.childN odes.length; i++) {
crawlDOM(node.c hildNodes[i],fnode,ftext);
}
fnode(node);
break;
case 3: // text node
ftext(node);
break;
}
}
---
Then you can do:
---
crawlDOM(docume nt.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.'