Skip to content

Instantly share code, notes, and snippets.

@mehdichaouch
Created July 26, 2016 09:03
Show Gist options
  • Save mehdichaouch/23963995f5e69aef17fe32510d45fb05 to your computer and use it in GitHub Desktop.
Save mehdichaouch/23963995f5e69aef17fe32510d45fb05 to your computer and use it in GitHub Desktop.
Javascript Regex to replace text NOT in html attributes
walk(document.body);
setTimeout(function() {
walk(document.body);
}, 1000);
function walk(node)
{
// Source: http://is.gd/mwZp7E
var child, next;
switch ( node.nodeType )
{
case 1: // Element
case 9: // Document
case 11: // Document fragment
child = node.firstChild;
while ( child )
{
next = child.nextSibling;
walk(child);
child = next;
}
break;
case 3: // Text node
handleText(node);
//imgFind(node);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment