Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // create a TreeWalker of all text nodes
- var allTextNodes = document.createTreeWalker(document.body,NodeFilter.SHOW_TEXT),
- // some temp references for performance
- tmptxt,
- tmpnode,
- // compile the RE and cache the replace string, for performance
- cakeRE = /cake/g
- replaceValue = "pie";
- // iterate through all text nodes
- while (allTextNodes.nextNode()) {
- tmpnode = allTextNodes.currentNode;
- tmptxt = tmpnode.nodeValue;
- tmpnode.nodeValue = tmptxt.replace(cakeRE,replaceValue);
- }
- // the innerHTML property of any DOM node is a string
- document.body.innerHTML = document.body.innerHTML.replace(/cake/g,'pie')
- var search_re = new RegExp("(?:>[^<]*)(" + stringToReplace + ")(?:[^>]*<)", "gi");
- // replace some chunk of stuff, the first section of your page works nicely
- // if you happen to have that organization
- //
- setTimeout(function() { /* replace the rest */ }, 10);
- var tmp = element.innerHTML.replace(search_re, whatever);
- /* more replace calls, maybe this is in a for loop, i don't know what you're doing */
- element.innerHTML = tmp;
- $('body').html($('body').html().replace('pie','cake'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement