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 trial

JavaScript JavaScript and the DOM (Retiring) Making Changes to the DOM Styling Elements

Sean Flanagan
Sean Flanagan
33,235 Points

The 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:

https://w.trhou.se/9b8hpzhks0

Thanks in advance for any help.

Sean

5 Answers

Steven Parker
Steven Parker
231,261 Points

There'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 of listDiv

Note that for proper behavior, it's the div (not the ul) that has the class. Thus the variable name "list‍Div".

Stuart Wright
Stuart Wright
41,120 Points

I 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
Steven Parker
231,261 Points

Don't add the class to the ul, it belongs on the div. See my answer.

Sean Flanagan
Sean Flanagan
33,235 Points

Hi 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
Sean Flanagan
33,235 Points

In index.html, line 11, I added,

 <div class="list">

Is that right?

Cheers

Steven Parker
Steven Parker
231,261 Points

Exactly right, assuming you mean you added the class to the div already there. :+1:

Sean Flanagan
Sean Flanagan
33,235 Points

Thank you Steven. Thank you both. ??

Sean