Let’s say you want to make all first letters of element with class big-title
into red
JS
window.onload = function(){ var elements = document.getElementsByClassName(".big-title"); 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"); } }
CSS
<style> .first-letter { color: red; } </style>
HTML
<div class="big-title">First letter of every word is now red!</div>