public
Created

wrap each word in a span

  • Download Gist
jquery.wordify.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11
$.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;
};

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.