Hide an element

Set the hidden attribute.

JavaScriptBrowser · DOM Version 1.0.0 · MIT · .md

hide-an-element.js
function hide(element) { element.hidden = true; }

Usage

Markup

fixture.html
<p id="notice">Saved</p>

Script

usage.js
const notice = document.querySelector('#notice');
hide(notice);
notice.checkVisibility(); // → false

Lines marked → were executed in headless Chromium against the markup above, and each result was compared with the value shown. Lines marked e.g. are illustrative.

Know the limits

  • hidden removes the element from layout and from the accessibility tree. A stylesheet rule such as display: flex overrides it; add [hidden] { display: none !important } to be safe.
  • visibility: hidden keeps the space. To hide content visually but keep it for screen readers, use a visually-hidden class instead.

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 Hide an element from the original 1loc collection by Nguyen Huu Phuoc, with iamdileepkumar, islamozbek. Copyright (c) 2020 phuoc-ng. MIT licensed.

Uses the hidden attribute; display and visibility trade-offs documented. Executed in Chromium. Original MDX retained as inert source evidence.

Maintained by Oveyon. Source commit: 14b481cf60df. Read the license.

Usage lines executed in headless Chromium against the fixture markup; no external services · reviewed October 28, 2026.

Keep exploring

Type two or more characters. Try “duplicate”, “webhook” or “retry”.