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 trialguram dgebuadze
Front End Web Development Techdegree Student 4,122 Pointsif (listDiv.style.display == 'none')
I tried to change statement and write: toggleList.addEventListener('click', () => { if (listDiv.style.display == 'block') { toggleList.textContent = 'show list'; listDiv.style.display = 'none'; } else { toggleList.textContent = 'hide list'; listDiv.style.display = 'block'; } }); Why isn't working if else statement in this case? Should we use querySelector everywhere as teacher says in this video?
2 Answers
Steven Parker
231,269 PointsIt would help to see the complete code, and with proper formatting, preferably in a link to a workspace "snapshot".
But just looking at this snippet, I don't see anything obviously wrong; but I notice that it depends on the variables "toggleList" and "listDiv", so perhaps they are not being established correctly. Or there could be an issue with the HTML part of the code.
guram dgebuadze
Front End Web Development Techdegree Student 4,122 PointsMy main question is what kind of display does list have in this case, because when I tried to equal in if statement { if (listDiv.style.display == 'block') or 'inline-block ' this statement was not equal neither cases.
Steven Parker
231,269 PointsBy default, the "display" property would be empty, and the display mode would be determined by the element type. A list normally uses "block" mode.