Skip to content

How to hide a DOM element using plain JavaScript

The Valley of Code

Your Web Development Manual

Find out how to hide and then show again elements in vanilla JavaScript

How do you hide a DOM element using plain JavaScript?

Every element exposes a style property which you can use to alter the CSS styling properties.

You can set the display property to β€˜none’ (like you would do in CSS, display: none;):

element.style.display = 'none'

To display it again, set it back to block or inline:

element.style.display = 'block'
β†’ Get my JavaScript Beginner's Handbook
β†’ Read my JavaScript Tutorials on The Valley of Code
β†’ Read my TypeScript Tutorial on The Valley of Code
  • THE VALLEY OF CODE (+ PRO), your web development manual
  • I wrote 15+ free coding BOOKS, download them here
  • SOLOPRENEUR LAND the missing MBA for wannabe solopreneurs craving a life with more freedom, control, fulfillment and purpose (summer 2024)