Using javascript, I randomly pick a word from a text in an html div tag and surround it with a span tag. Using the class of the span tag I try to perform a CSS transition of the word color from black to red. I then remove the span tag to change the word back to black color. The effect I am looking for are "flashing words".
I manage to get the word to change color, but can not get the smooth CSS transition to work.
My question is: Why isn't the CSS transition working?
My problem seems similar to this question, but I do not manage to get the solution of "forcing a layout" to work in my case.
I hope it is ok to provide a working link to the test code I am working with instead of posting code here (javascript file here). If not, I will of course on request add code to this post.
Thank you in advance! I have been busting my head against this problem for a full day without success. Time to acknowledge that I need help with this one :-)
Edit: Adding code.
HTML:
<div id="message">
Some words here.
</div>
CSS:
div#message span
{
color: black;
}
div#message span.redtext
{
transition: color 5s ease-out 0s;
color: red;
}
Javascript:
//Insert span around word
var newText = text.split(randomWord).join('<span>' + randomWord + '</span>');
$("#message").html(newText);
//Request property that requires layout to force a layout
var x = $("#message").clientHeight;
//Add class to span
var newText = newText.split('<span>').join('<span class="redtext">');
$("#message").html(newText);