

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set an element's display type with JavaScript?
To set an element’s display type, use the display property. If you want to hide the element, then use none.
Example
You can try to run the following code to set an element's display type with JavaScript −
<!DOCTYPE html> <html> <head> <style> #myID { width: 250px; height: 200px; background-color: green; } </style> </head> <body> <button onclick="display()">Set display as none</button> <div id="myID"> <h1>Heading Level 1 for Demo</h1> This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. </div> <script> function display() { document.getElementById("myID").style.display = "none"; } </script> </body> </html>
- Related Questions & Answers
- How to set the width of an element's border with JavaScript?
- How to set the style of an element's border with JavaScript?
- How to set the type of positioning method used for an element with JavaScript?
- How to display HTML element with JavaScript?
- How to set the padding of an element with JavaScript?
- How to set the height of an element with JavaScript?
- How to set the margins of an element with JavaScript?
- How to set the type of cursor to display for the mouse pointer with JavaScript?
- How to set the top position of an element with JavaScript?
- How to set the bottom padding of an element with JavaScript?
- How to set the left padding of an element with JavaScript?
- How to set the top padding of an element with JavaScript?
- How to set the right padding of an element with JavaScript?
- How to set the left margin of an element with JavaScript?
- How to set the horizontal alignment of an element with JavaScript?
Advertisements