Create a gist now

Instantly share code, notes, and snippets.

Embed
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>');
textnode.replaceWith(text);
});
return this;
};
@subwaymatch

This comment has been minimized.

Show comment
Hide comment
@subwaymatch

subwaymatch May 11, 2017

A very smart solution, thanks.

A very smart solution, thanks.

@killa-kyle

This comment has been minimized.

Show comment
Hide comment
@killa-kyle

killa-kyle Mar 29, 2018

Thanks, this helps a lot.

Thanks, this helps a lot.

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