Skip to content

Instantly share code, notes, and snippets.

@yukulele
Created January 28, 2014 14:49
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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;
};
@subwaymatch
Copy link

A very smart solution, thanks.

@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