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();
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()