Skip to content

Instantly share code, notes, and snippets.

@PauliusKrutkis
Created March 12, 2017 20:21
Show Gist options
  • Save PauliusKrutkis/1a6e0433a697e3cb4ca39546b049078b to your computer and use it in GitHub Desktop.
Save PauliusKrutkis/1a6e0433a697e3cb4ca39546b049078b to your computer and use it in GitHub Desktop.
jQuery first word selector script
var firstWord = (function($) {
var selector = '.first-word';
$(selector).each(addWrap);
function addWrap() {
var word = $(this).html();
var index = word.indexOf(' ');
if (index == -1)
index = word.length;
$(this).html('<span class="first">' + word.substring(0, index) + '</span>' + word.substring(index, word.length));
}
})(jQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment