This code:
const mobileNavShow = document.querySelector('.mobile-nav-show');
only looks through the index.html of my project, while my navbar is in navbar.html and is out of the scope of querySelector. I used w3’s w3-include-html
to link the two. If I copy the contents of navbar.html into the body of index.html, my navbar works as intended. I am unsure of the technical terms of the problem I am facing.
I tried to create a navbar in a separate HTML file, but js “document.querySelector(‘X’)” is unable to find elements in the other HTML file.
New contributor
Siddharth Pothini is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.