Skip to content
Advertisement

How to change the style of HTML list items using setInterval in JavaScript?

I have a HTML code with 3 list items and the ids for my ul is ‘exercise6-list’

JavaScript

I need to make each li glow for three seconds and repeat itself

So far I have written:

JavaScript

*I’m very new to programming, but thank you for your help

Advertisement

Answer

To make a timed function we use setInterval, and add the class “glow” to the current element, and remove that class from the previous one.
To cycle through the elements, we use an index-variable, which increases per cycle and loops back around when necessary.

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