why is this code not working? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

why is this code not working?

const menuToggle = document.querySelector('.menu-toggle input') const nav = document.querySelector('nav ul') menuToggle.addEventListener('click', function(){ nav.classList.toggle('slide'); }); https://code.sololearn.com/W7St8Oz2IMMy/?ref=app

26th Jan 2023, 5:11 PM
Akmal Kv
Akmal Kv - avatar
3 Answers
+ 2
your javascript is run before html is loaded. which makes some variables null. put your code inside this function. window.onload = function(){ //your code }
26th Jan 2023, 6:08 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 5
Can you tag the language for your question? Also, it would be easier to say what's wrong if you could attach your whole code from the code playground. Thanks https://code.sololearn.com/W3uiji9X28C1/?ref=app
26th Jan 2023, 5:15 PM
Ausgrindtube
Ausgrindtube - avatar
+ 1
thank you.....
26th Jan 2023, 9:54 PM
Akmal Kv
Akmal Kv - avatar