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"; }

1
  • You need to reset the animation property and then reassign it to restart the animation. Commented Oct 27, 2022 at 5:16

1 Answer 1

0

Can you try this?

function myFun()

{
    document.getElementById('myDiv').style.animation = null ;
    document.getElementById('myDiv').style.animation = "animation 1s forwards"; 
}
Sign up to request clarification or add additional context in comments.

4 Comments

Not working, I just want run function from beginning evry time when button clicked.
document.getElementById('myDiv').style.animation = 'none'; try this also
I can't try your code. So I don't know if it will work
document.getElementById('myDiv').style.animation = 'none'; yes it's worked but i want the same thing with one button

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.