ClassList.toggle().....is not working...plz answer me guys.... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

ClassList.toggle().....is not working...plz answer me guys....

Everytime I use classlist in sololearn it gives me error like classlist.toggle is undefined....how to fix it??

16th Apr 2022, 3:45 PM
Arpit Shukla
Arpit Shukla - avatar
14 Answers
+ 2
Here's an example of adding the event after html is loaded: https://code.sololearn.com/W7Ppyku1Pmp4/?ref=app
16th Apr 2022, 4:30 PM
Lisa
Lisa - avatar
+ 2
Can you please link your code (put it on sololearn playground)?
16th Apr 2022, 3:58 PM
Lisa
Lisa - avatar
+ 1
it's classList, note the capital L
16th Apr 2022, 3:53 PM
Lisa
Lisa - avatar
+ 1
Problem is with sololearn app @arpit.
16th Apr 2022, 4:12 PM
Tech Giant
Tech Giant - avatar
0
Lisa i have done it....but still it's not working
16th Apr 2022, 3:56 PM
Arpit Shukla
Arpit Shukla - avatar
0
Lisa its working fine on other ide but not on sololearn
16th Apr 2022, 3:57 PM
Arpit Shukla
Arpit Shukla - avatar
0
@lisa yes sure
16th Apr 2022, 4:01 PM
Arpit Shukla
Arpit Shukla - avatar
16th Apr 2022, 4:04 PM
Arpit Shukla
Arpit Shukla - avatar
0
It could be a loading order issue, that means for example the Javascript is loaded before the html is completely loaded and the js cannot find the html elements There are multiple ways to fix this: A) query the html element inside the function function toggle() { let nav = document.querySelector('.links'); nav.classList.toggle("active"); } B) But all js code inside of window.onload and then add your toggle function via js to the html element (addEventListener...) window.onload = function() { // Here your js // add toggle() to html element }
16th Apr 2022, 4:12 PM
Lisa
Lisa - avatar
0
Tech Giant ok bhai thanku
16th Apr 2022, 4:19 PM
Arpit Shukla
Arpit Shukla - avatar
0
@lisa ok I'll try thanku so much
16th Apr 2022, 4:20 PM
Arpit Shukla
Arpit Shukla - avatar
0
They just fix my comment section for me, am happy , now I can post thank you. You guys are awesome
18th Apr 2022, 11:00 AM
D K Eric
D K Eric - avatar
0
How can add link in the center of playground
18th Apr 2022, 3:43 PM
Shivaji Bhosle
- 1
Bhjk
17th Apr 2022, 12:37 AM
Vivek Kumar