I'm using treewalker to replace matched words on the current page from an object.
Im' running into one issue where it is replacing a matched word that is the path of an img and not a text node.. any ideas?
var a = finalList;
var walk = document.createTreeWalker(document, NodeFilter.SHOW_TEXT, null, false), n;
while(n = walk.nextNode()) {
//n.nodeValue = n.nodeValue.replace(/foo/g, 'bar');
for (var i = 0; i < a.length; i++) {
var item = a[i];
var text = item.text;
var frequency = item.frequency;
var re = new RegExp(text, 'gi');
replaced = $("body").html().replace(re, frequency);
$("body").html(replaced);
console.log(text, " replaced with: ", frequency);
}
}
EDIT* finalList looks like:
finalList = {bla: 100, foo: 200, baz: 300}