Ask coding questions

← Back to all posts
Js not working
sn236

Hi, so I was working on an animation and I wanted when the user clicks then the animation should play. So I used animation play state which pauses or runs the animation. But when I added the js it gave me an error -
TypeError: Cannot read properties of undefined (reading'animationPlayState') at move (/script.js:3:15) at HTMLDivElement.onclick (/:12:54)
Is there a way to fix this using js or css.

Answered by SixBeeps [earned 5 cycles]
View Answer
Voters
sn236
Comments
hotnewtop
SixBeeps

document.querySelectorAll returns a list of elements, not just one. So, x.style doesn't exist (lists don't have styles) and therefore trying to read x.style.animationPlayState will throw an error.

sn236

@SixBeeps Thanks