Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSean Flanagan
33,235 PointsThe Hide button doesn't work
Hi there.
My Hide button doesn't hide the list.
In the console I get this:
app.js:8 Uncaught ReferenceError: list is not defined
at HTMLButtonElement.toggleList.addEventListener (app.js:8)
Here's my workspace:
Thanks in advance for any help.
Sean
5 Answers
Steven Parker
231,261 PointsThere's two issues:
- on line 11 of index.html, the
<div>
element should have the class of "list" (wasn't it there originally?) - on line 8 of app.js you have
list
instead oflistDiv
Note that for proper behavior, it's the div (not the ul) that has the class. Thus the variable name "listβDiv".
Stuart Wright
41,120 PointsI made two changes to your code to fix this.
First, in the JavaScript, you have:
if (list.style.display === "none") {
But earlier you called your variable listDiv, not list. So you should edit the above line to:
if (listDiv.style.display === "none") {
Secondly, your listDiv variable does not correctly target the list. It is looking for an element with class "list", which does not exist in your HTML. There are a few ways you could fix this, but I opted for adding a class of list to your HTML:
<ul>
to
<ul class="list">
Steven Parker
231,261 PointsDon't add the class to the ul, it belongs on the div. See my answer.
Stuart Wright
41,120 PointsD'oh! Yes of course.
Sean Flanagan
33,235 PointsHi gentlemen.
I'm totally annoyed with myself. I read your posts and then looked at the video and I saw what I'd done wrong. It confirms what you say.
I've made the necessary corrections and the Show/Hide button works fine now.
Thank you both
Sean
Sean Flanagan
33,235 PointsIn index.html, line 11, I added,
<div class="list">
Is that right?
Cheers
Steven Parker
231,261 PointsExactly right, assuming you mean you added the class to the div
already there.
Sean Flanagan
33,235 PointsThank you Steven. Thank you both. ??
Sean