Skip to content

Instantly share code, notes, and snippets.

@vishaltelangre
Created April 8, 2014 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vishaltelangre/10116361 to your computer and use it in GitHub Desktop.
Save vishaltelangre/10116361 to your computer and use it in GitHub Desktop.
Replace every character from a DOM node with desired character
function replaceEveryCharOf( selector, withChar, ignoreSpace ) {
$(selector).contents().filter(function() {
return this.nodeType == 3;
}).each(function(){
var regex = ignoreSpace ? /[^\s.]/g : /./g;
this.textContent = this.textContent.replace(regex, withChar);
});
}
// Usage:
replaceEveryCharOf($('*'), '■', true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment