Skip to content
Advertisement

React: Change / Iterate an Element Color Every Second

Coding World

JavaScript

Say I have the above, I want to iterate through each element one at a time and turn the colour to gold.

So at any one time only one of the words should be gold. First Hello should be gold, then Coding should be gold and then World should be gold.

I tried to do it so it would change every second. There are example of how to change a colour every second but I can’t find an example of how to do it with three different element and so they don’t clash.

See my woeful attempt below

JavaScript

Advertisement

Answer

Using setInterval it can be done as follows

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement