JSFiddle - React, Tailwind, and code Playground

HTML

<div id="message">
Testing changing text color
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 
</div>

CSS

.redtext {
    color: #f00;
}

JavaScript

//ColorChanger for text
function colorChanger()
{
    //Get text and choose random word
    var text = $("#message").html();
    var words = ($.trim(text)).split(/\s+/);
    var randomWordIndex = Math.floor(Math.random()*words.length);
    
    //Insert span around word
    var newText = text.split(words[randomWordIndex]).join('<span class="highlightedWord">' + words[randomWordIndex] + '</span>');
    $("#message").html(newText);
    
    //Request property that requires layout to force a layout 
    var x = $("#message").clientHeight;
    
    //Add class to span
    $(".highlightedWord").addClass("redtext");

    //Wait before removing span
    setTimeout(function(){changeBack(text);}, 5000);
}

function changeBack(text)
{
    //Remove span. (Maybe need to remove class first in a separate step, as when inserting?)
    $(".highlightedWord").removeClass("redtext");
}//ColorChanger for text


colorChanger();