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 trialdeepak sharma
3,844 PointsIn this styling elements section why use ( listDiv.style.display = 'block'; ). why use it display to block.why?
toggleList.addEventListener('click', () => {
if (listDiv.style.display === 'none' ) {
toggleList.textContent = 'Hide list';
listDiv.style.display = 'block';
} else {
toggleList.textContent = 'Show list';
listDiv.style.display = 'none';
});
question: what is the reason behind using display block?
2 Answers
Bogdan Cabaj
16,349 PointsDIV by default has a display=block. Since you are setting it to none (hiding the div) you have to set it back to block if you want to show it.
Doug Hawkinson
Full Stack JavaScript Techdegree Student 25,073 PointsActually, I'm not sure whether you are asking "Why use 'block' as opposed to (maybe) 'inline' or 'block' as opposed to 'none'. My guess is from the limited context that it is, as opposed to 'none', in which case, I agree with Bogdan. The 'none' hides the object and you need a way to 'unhide' the object. That would be 'block' or another of the visible display properties like 'inline' or 'inline-block'. But probably 'block'. Sorry, if I seem to be equivocating. Its just such limited context.
ywang04
6,762 Pointsywang04
6,762 PointsI see. Thanks a lot.