Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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>');
return this;

A very smart solution, thanks.

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