Skip to content

Instantly share code, notes, and snippets.

@accrane
Created March 6, 2017 16:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save accrane/53ffdc88f7b062c6cce2e4efacd5693b to your computer and use it in GitHub Desktop.
Save accrane/53ffdc88f7b062c6cce2e4efacd5693b to your computer and use it in GitHub Desktop.
jQuery solution to changing the styling of the first word
/*
*
* Make first word in date underlined
*
------------------------------------*/
$('.js-first-word').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.shift(); // shift the first word
first_part = word_array.join(' '); // rejoin the first words together
heading.html(['<span class="e-date">', last_word, '</span> ' , first_part].join(''));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment