I have a HTML page with which I want to do some client side replacement using Javascript. The values I would like to replace are in an array like so:
var searchFor = new Object(); var replaceWith = new Object(); searchFor = [ 'quick', 'brown', 'fox', ]; replaceWith = [ 'nimble', 'black', 'cat', ];
So every instance of ‘brown’ should be replaced by ‘black’. What’s the easiest way to do this that works cross browser?
I would recurse into all nodes of the DOM using default W3C DOM traversal, picking the text nodes only for processing: