Skip to content

Instantly share code, notes, and snippets.

@karamansky
Created February 28, 2023 13:54
Show Gist options
  • Save karamansky/79031b88065d8a6e11d1c55ee85ec656 to your computer and use it in GitHub Desktop.
Save karamansky/79031b88065d8a6e11d1c55ee85ec656 to your computer and use it in GitHub Desktop.
/**
* Add class to first word in text-block/tag by class '.styling-first-word'
*/
function addClassToFirstWord() {
let first_word_class = 'first-word';
let el = jQuery('.styling-first-word');
el.each(function(){
let string = jQuery(this).html();
let first_word = string.split(" ");
let html =
"<span class=" + first_word_class + ">"
.concat(first_word[0], "</span>") + "&#32;" + string
.substr(string.indexOf(" ") + 1);
jQuery(this).html(html);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment