getElementbyID works since IDs have to be unique and thus the function always returns exactly one element (or null if none was found). Got struck with the class name. How can i add the style.animation to the class name ?
function myFunction() {
document.getElementsByClassName("myDIV").style.WebkitAnimation = "mynewmove 4s 2";
document.getElementsByClassName("myDIV").style.animation = "mynewmove 4s 2";
}
.myDIV {
width: 100px;
height: 100px;
background: red;
position: relative;
-webkit-animation: mymove 1s infinite;
/* Chrome, Safari, Opera */
animation: mymove 1s infinite;
}
@-webkit-keyframes mymove {
from {
left: 0px;
}
to {
left: 200px;
}
}
@-webkit-keyframes mynewmove {
from {
top: 0px;
}
to {
top: 200px;
}
}
@keyframes mymove {
from {
left: 0px;
}
to {
left: 200px;
}
}
@keyframes mynewmove {
from {
top: 0px;
}
to {
top: 200px;
}
}
<button onclick="myFunction()">Try it</button>
<div class="myDIV"></div>