How to replace all occurrences of a string in a HTML page using Javascript
问题 I know this question may be asked before but I did not find the correct answer that works. I tried this code $('body *').each(function(k,v){$(v).text($(v).text().replace("Hazem","mizzo"))}); but the page crashes, I don't know why. I'm prefer the code to be in pure javascript not jQuery. Thanks. 回答1: You should walk the DOM, find text nodes, and replace the found text in each. Here's a simple example. You can make walkText() more generic by passing a callback that does the replacement.