why property javascript(classList) in sololearn can't read? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

18th Sep 2019, 8:37 PM
WAHYU OKI SAPUTRA
WAHYU OKI SAPUTRA - avatar
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
19th Sep 2019, 1:20 AM
Zephyr Koo
Zephyr Koo - avatar
+ 1
Zephyr Koo THANK YOU!!
19th Sep 2019, 1:28 AM
WAHYU OKI SAPUTRA
WAHYU OKI SAPUTRA - avatar
0
can i see the code ?
18th Sep 2019, 9:01 PM
Taste
Taste - avatar
0
Taste var icon = document.getElementsByClassName("icon")[0]; function toggle(){ icon.classList.toggle("active"); } https://code.sololearn.com/W6wjXqZ3C4JS/?ref=app
18th Sep 2019, 10:44 PM
WAHYU OKI SAPUTRA
WAHYU OKI SAPUTRA - avatar
0
Can't read property 'classList' of undefined
18th Sep 2019, 10:46 PM
WAHYU OKI SAPUTRA
WAHYU OKI SAPUTRA - avatar
0
wahyuokiss You're welcome! 😊
19th Sep 2019, 4:02 AM
Zephyr Koo
Zephyr Koo - avatar