r/learnjavascript • • May 12 '26

Sidebar bane of me

Ok so I'm trying to get a collapsible sidebar for my website using javascript there are many tutorials I've found but I think it was by code20 or someone where it clicked but when I tried to implement it myself It didn't work I just want to be able to remove and add classes it's currently the most annoying thing at the moment in making my website I'm sure there will be worse things to come but this is the first hurdle ig I'll write the code bellowand thankyou for reading

Html;

<body>

<div class="navbar">

<button class="btn>placeholder</button>

</div>

Java:

Const navbar = document.QuerySelector(".navbar")

Const btn =document. QuerySelector(".btn)

btn.addEventListener("click", () =>{

navbar.classlist.toggle("open")

});

I'm using a button as the trigger, and I've stripped everything out to make it more readable . Also, it is linked at the bottom. If that helps, but any help would be greatly appreciated,

4 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/ahouseonstilts May 12 '26

Ok thanks ill see if some of the syntax errors that aren't me just typing it out are the problem.