Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jonschr
Created November 10, 2015 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonschr/594e454fa06a4c5cbadf to your computer and use it in GitHub Desktop.
Save jonschr/594e454fa06a4c5cbadf to your computer and use it in GitHub Desktop.
A javascript snippet to wrap just one word with a container
jQuery(document).ready(function( $ ) {
$('.word-highlight').each(function() {
var word = $(this).html();
var index = word.indexOf(' ');
if(index == -1) {
index = word.length;
}
$(this).html('<span class="first-word">' + word.substring(0, index) + '</span>' + word.substring(index, word.length));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment