Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Sean Flanagan
Sean Flanagan
33,233 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
218,528 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,102 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
218,528 Points

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

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

In index.html, line 11, I added,

 <div class="list">

Is that right?

Cheers

Steven Parker
Steven Parker
218,528 Points

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

Sean Flanagan
Sean Flanagan
33,233 Points

Thank you Steven. Thank you both. ??

Sean