0
why property javascript(classList) in sololearn can't read?
vanilla javascript https://code.sololearn.com/W6wjXqZ3C4JS/?ref=app https://code.sololearn.com/W6wjXqZ3C4JS/?ref=app
6 Answers
+ 1
Good day wahyuokiss! You've encountered a fairly common issue in SoloLearn due to the order execution of JavaScript.
The reason is the DOM in body haven't loaded yet when the JavaScript get executed and therefore the target element is always null/undefined.
One way would be move the entire piece of JavaScript before the end of body or wrap it in the onLoad event to ensure the DOM was fully loaded before trying to query it and process it.
You may find this useful:- đ
https://code.sololearn.com/WXe61FrE4YD4
+ 1
Zephyr Koo THANK YOU!!
0
can i see the code ?
0
Taste
var icon = document.getElementsByClassName("icon")[0];
function toggle(){
icon.classList.toggle("active");
}
https://code.sololearn.com/W6wjXqZ3C4JS/?ref=app
0
Can't read property 'classList' of undefined
0
wahyuokiss You're welcome! đ