How to change the color of the specific portion of a string wrapped in a div:
We have a div like this:
<div id="text" class="text-class">Stack Overflow is the largest, most trusted online community for developers </div>
How we can change the color of the 'trusted online community' portion to red using the code template below?
let text = document.getElementById("text");
// We want to only change the color of this portion of the text
changeColor('trusted online community');
function changeColor(portion){
// code to change the text color
...
// function to animate the color from black to red
function changeToRed(el) {
el.classList.add("colorRed");
}
};
.colorRed {
animation: colorRedAnime 0.8s cubic-bezier(0.785, 0.135, 0.15, 0.86);
animation-fill-mode: forwards ;
}
@-webkit-keyframes colorRedAnime {
from { color: #808080 }
to { color: #e80000 }
}
<div class="container">
<div id="text" class="text-class">Stack Overflow is the largest, most trusted online community for developers </div>
</div>