Created
January 28, 2014 14:49
-
-
Save yukulele/8668962 to your computer and use it in GitHub Desktop.
wrap each word in a span
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, this helps a lot.