Created
February 28, 2023 13:54
-
-
Save karamansky/79031b88065d8a6e11d1c55ee85ec656 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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>") + " " + 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