Skip to content

Instantly share code, notes, and snippets.

@yukulele
Created January 28, 2014 14:49
Show Gist options
  • Save yukulele/8668962 to your computer and use it in GitHub Desktop.
Save yukulele/8668962 to your computer and use it in GitHub Desktop.
wrap each word in a span
$.fn.wordify = function(){
this.find(":not(iframe,textarea)").addBack().contents().filter(function() {
return this.nodeType === 3;
}).each(function() {
var textnode = $(this);
var text = textnode.text();
text = text.replace(/([^\s-.,;:!?()[\]{}<>"]+)/g,'<span>$1</span>');
textnode.replaceWith(text);
});
return this;
};
@killa-kyle
Copy link

Thanks, this helps a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment