I need to wrap each asterisks on a page with . The few things I\'ve tried don\'t work. I think what this boils down to is
This will work and not replace * in tags it shouldn't.
http://jsfiddle.net/DR6Ca/2/
var text = $("body").find(":contains(*)").contents().filter(function() {
//Don't include css or script tags, all other text nodes are fine.
return this.nodeType == 3
&& ($(this).parent().get(0).tagName.toUpperCase() !== "SCRIPT")
&& ($(this).parent().get(0).tagName.toUpperCase() !== "STYLE");
}).replaceWith(function() {
return this.textContent.replace(/\*/g, "*");
You can test the others code in this jsfiddle to see if they keep the "hi" blue or not. If it doesn't stay blue they have a bug.