Show an element
Clear the hidden attribute and any inline display: none.
function show(element) { element.hidden = false; element.style.removeProperty('display'); }
Usage
Markup
<p id="notice" hidden>Saved</p>
Script
const notice = document.querySelector('#notice');
show(notice);
notice.checkVisibility(); // → true
Know the limits
- If a stylesheet hides the element, it stays hidden; toggle a class instead.
- The original only cleared the inline display value, so an element hidden with the hidden attribute stayed hidden.
The function above is the code the usage lines run. It does not validate its arguments; add checks where it receives untrusted input.
Source & maintenance
Based on Show an element from the original 1loc collection by Nguyen Huu Phuoc. Copyright (c) 2020 phuoc-ng. MIT licensed.
Clears the hidden attribute as well as inline display: none. Executed in Chromium. Original MDX retained as inert source evidence.
Maintained by Oveyon. Source commit: 14b481cf60df. Read the license.
Keep exploring
- Check if a given DOMRect is contained within another DOMRect — True when the target lies inside the container or on its edges.
- Check if two DOMRects intersect — Two rects intersect when they meet on both axes.
- Compare two DOMRects for size and position match — Compare x, y, width and height exactly.