Reputation: 1
I tried to make a SVG animation. But It can't change color in SVG element when I clicked Red Cheeks button. Maybe, I think that javascript selector is wrong. Because sometimes, it worked only LeftCheek when I used querySelectorAll method.
And console showed this error message. but I can't understand how I fix it.
main.js:11 Uncaught TypeError: Cannot read property 'add' of undefined(…)changeCharactor @ main.js:11
My code is here(code pen).
If my explain is unclear, Please comments. Thanks :-)
Upvotes: 0
Views: 84
Reputation: 14053
The cheek
variable is set to a DOMList, which is sort of like an array of elements.
var cheek = document.getElementsByClassName("cheeks");
As such, it doesn't have a classList
property. Instead, individual elements of the list have that property.
cheek[0].classList.add('...whatever');
Upvotes: 1