 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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 the opacity level for an element with JavaScript?
Use the opacity property in JavaScript to set the opacity level. You can try to run the following code to set the opacity level for an element with JavaScript −
Example
<!DOCTYPE html> <html>    <head>       <style>          #box {             width: 450px;             background-color: gray;          }       </style>    </head>    <body>       <p>Click below to set Opacity.</p>       <button type="button" onclick="display()">Set Opacity</button>       <div id="box">          <p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>          <p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>          <p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>       </div>       <br>       <script>          function display() {             document.getElementById("box").style.opacity = "0.5";          }       </script>    </body> </html>Advertisements
 