Skip to content

Instantly share code, notes, and snippets.

@Sanabria
Forked from ramseyp/last-word.js
Last active August 29, 2015 14:12
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 Sanabria/2a896b52a62c702d60ce to your computer and use it in GitHub Desktop.
Save Sanabria/2a896b52a62c702d60ce to your computer and use it in GitHub Desktop.
jQuery(document).ready(function($){
$('h2.title').html(function(){
// separate the text by spaces
var text= $(this).text().split(' ');
// drop the last word and store it in a variable
var last = text.pop();
// join the text back and if it has more than 1 word add the span tag
// to the last word
return text.join(" ") + (text.length > 0 ? ' <span class="last">'+last+'</span>' : last);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment