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

explanation about this code

toggleButton.addEventListener("click", () => {
  //if the display is default click tp hide the list                  
 if(listDiv.style.display == "none") {
  toggleButton.textContent = "Hide list";
  listDiv.style.display = "block"
} else {
  toggleButton.textContent = "Show list";
   listDiv.style.display =  "none"; 

someone can explain to me the statment in the if block?

I know that "none" means to literally hide it and "block" means its deafult.

why we check if the listDiv.style.display is equal to "none" if it can't be "none" since when we open the page we see the list.

1 Answer

"none" means to literally hide it and "block" means its deafult or to show. We started with 'none', however I agree that it would be more logical to start with 'block'. Functionally it's this same.