Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

425
Views
How to change opacity of a div on button click using JS?

I am trying to add a script to my HTML file that changes the opacity of a div when a button is clicked.

This is the HTML file

This is the CSS file

This is my function

Essentially what I'm trying to achieve is the div that is currently set to 0 opacity, will be change to 1 opacity on the click of the button. Currently this is not working, and I am relatively new to incorporating JS in and HTML file. Any tips would be greatly appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here's a simple example using JavaScript embedded in HTML. Make sure you're using an event listener that listens for the click of your button.

<!DOCTYPE html>
<html>
  <head>
    <title>About Me</title>
  </head>
  <body>
    <h1 style="opacity: 0;">About Me</h1>
    <button>
      Show
    </button>
    <script>
      var button = document.querySelector('button');
      button.addEventListener('click', function() {
        var h1 = document.querySelector('h1');
        h1.style.opacity = 1;
      });
    </script>
  </body>
</html>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!