Skip to content

Instantly share code, notes, and snippets.

@webhasan
Created January 26, 2014 06:39
Show Gist options
  • Save webhasan/8629389 to your computer and use it in GitHub Desktop.
Save webhasan/8629389 to your computer and use it in GitHub Desktop.
js: target very first latter of words
window.onload = function(){
var elements = document.getElementsByClassName("each-word")
for (var i=0; i<elements.length; i++){
elements[i].innerHTML = elements[i].innerHTML.replace(/\b([a-z])([a-z]+)?\b/gim, "<span class='first-letter'>$1</span>$2")
}
}
<style>
.first-letter {
color: red;
}
</style>
<p class="each-word">First letter of every word is now red!</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment