0

This is a simple function, which works to do animation in my div with the help of onclick event. I want the animation to be restarted on every click, in other words, the function is reset after the completion of the function, and when the button is clicked again, the animation will happen.

#myDiv {animation: none;}

function myFun() { document.getElementById('myDiv').style.animation = "animation 1s forwards"; }

  • You need to reset the animation property and then reassign it to restart the animation. – Terry Oct 27 '22 at 05:16

1 Answers1

0

Can you try this?

function myFun()

{
    document.getElementById('myDiv').style.animation = null ;
    document.getElementById('myDiv').style.animation = "animation 1s forwards"; 
}