freecoding.school100% FREE · NO SIGNUP
The Old NetISSUE #52 of 60

show / hide patterns · display · visibility

Pixel PeteVSQuirks Mode
Pixel Pete saysShow/hide patterns toggle visibility with display:none or the hidden attribute.

The simplest interactivity: hide and reveal content. Set el.style.display = "none" (removes from layout) or toggle the hidden property/attribute. visibility:hidden hides but keeps the space. Driving this through a CSS class (.is-hidden { display:none }) is cleaner than inline styles and the basis of menus, tabs, and disclosures.

Power-ups you unlock

Quirks Mode attacks — common mistakes

Boss battleToggle a panel’s visibility on a button click via a CSS class.

Example code

<!doctype html><html><head><meta charset="utf-8"><style>.hide{display:none}</style></head>
<body style="background:#06040d;color:#e6e0ff;padding:20px"><button id="b">toggle</button><p id="p">now you see me</p>
<script>document.getElementById('b').onclick=()=>document.getElementById('p').classList.toggle('hide');</script></body></html>
▶ Open the interactive comic issue
‹ Timing · SetTimeout · SetInterval · ClearTimeoutToggle Patterns · ClassList.Toggle ›