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<noob />
17,062 Pointsexplanation 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
Piotr Manczak
Front End Web Development Techdegree Graduate 29,363 Points"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.