JavaScript JavaScript and the DOM Making Changes to the DOM Styling Elements

Nuriddin Ikramov
Nuriddin Ikramov
4,100 Points

The code explanation

I have two questions: 1) Could you explain the conditional statement? I dont understand why I should use if(listDiv.style.display=='none'), as the default value of display is 'block'? Why does it enter the first statement?

1 Answer

Steven Parker
Steven Parker
177,522 Points

The default value of style.display is not "block", it's simply an empty string ("").

For some elements (for example, "div") the default display mode is block, but that default is overridden when something is assigned directly to the style.display attribute.