Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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