- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM Style visibility Property
The HTML DOM style visibility property returns and modify whether an element should be visible or not in an HTML document.
Syntax
Following is the syntax −
Returning visibility
object.style.visibility
Modifying visibility
object.style.visibility = “value”
Values
Here, value can be −
Value | Explanation |
---|---|
initial | It set this property value to its default value. |
inherit | It inherits this property value from its parent element. |
hidden | In it the element is not visible but still its presence will affect the layout. |
visible | In it the element is visible. |
collapse | In it the element in table row or column is not visible but still its presence will affect the layout. |
Example
Let us see an example of HTML DOM style visibility property −
<!DOCTYPE html> <html> <head> <style> body { color: #000; background: lightblue; height: 100vh; } .btn { background: #db133a; border: none; height: 2rem; border-radius: 2px; width: 40%; display: block; color: #fff; outline: none; cursor: pointer; margin: 1rem 0; } </style> </head> <body> <h1>DOM Style visibility Property Example</h1> <p>I'm paragraph element with some dummy text</p> <button onclick="add()" class="btn">Set visibility</button> <script> function add() { document.querySelector('p').style.visibility = "hidden"; } </script> </body> </html>
Output
This will produce the following output −
Click on “Set visibility” button to set visibility with hidden as value on paragraph element −
Advertisements