how to start animation css with javascript code example

Example 1: js start css animation

const element = document.querySelector(".yourElementClass");
const btn = document.querySelector(".yourButtonClass");

btn.onclick = () => {
  element.style.animation = "YourAnimation 1s linear infinite"
}
// you will need js to start an animation, Don't forget to declare it using css

Example 2: start animation with javascript

element.addEventListener("click", function(e){
  element.classList.remove("anim");
  setTimeout(() => element.classList.add("anim"), 0);
}, false);

Tags:

Css Example