var x = document.getElementsByClassName("box");
// Code for Chrome, Safari and Opera
x.addEventListener("webkitAnimationEnd", function(){
console.log("event has ended");
});
// Standard syntax
x.addEventListener("animationend", function(){
console.log("event has ended");
});
.box {
background: red;
position: absolute;
padding: 100px;
}
.box:hover {
animation-name: rotate;
animation-duration: 2s;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
@keyframes rotate {
from {transform: rotate(0deg);}
to {transform: rotate(360deg);}
}
<html>
<body>
<div class="box">
</div>
</body>
</html>
I'm trying to use js with css animations, im trying to display a message in the console log that the animation has ended but it not appearing, it gives me this error: x.addEventListener is not a function here is my code: