Skip to content

Instantly share code, notes, and snippets.

Last active March 22, 2016 19:35
What would you like to do?
$(document).ready(function() {
$('.js-title').each(function(index, element) {
var heading = $(element);
var word_array, last_word, first_part;
word_array = heading.html().split(/\s+/); // split on spaces
last_word = word_array.pop(); // pop the last word
first_part = word_array.join(' '); // rejoin the first words together
heading.html([first_part, ' <span class="last-word">', last_word, '</span>'].join(''));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment