Skip to content

Instantly share code, notes, and snippets.

@matiangul
Last active December 17, 2015 20:49
Show Gist options
  • Save matiangul/5670745 to your computer and use it in GitHub Desktop.
Save matiangul/5670745 to your computer and use it in GitHub Desktop.
Split words in sentence into lines
base.breakAfterWhiteSpace = function() {
var $el = $(this),
text = $el.text(),
splitted = text.split(' '),
newText = splitted[0];
for(var i=1;i<splitted.length; i++) {
newText = newText + '</br>' + splitted[i];
}
console.log(newText);
$el.html(newText).addClass('splitted');
};
$('.break-line-after-space:not(.splitted)').each(base.breakAfterWhiteSpace);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment