'Click the button again to stop animation after 4 seconds

I have a statement if its true it clicks the button to play the animation, I want it to click the button again after 4 seconds to stop the animation. Below is the code in the if statement.

document.getElementById("clickButton").click();


Solution 1:[1]

You can see answers here : CSS Animations, start and stop infinite animation on click And for after 4 seconds to stop the animation , You can Use setTimeout() or setInterval()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sam10