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

157
Views
Activating CSS through a HTML button press

I was wondering if you can activate some CSS through an HTML button press or scrolling to a certain point. It's preferred if it's through JS.

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

You can use a wrapper class:

const button = document.querySelector("button")
button.addEventListener("click", () => {
  document.body.classList.add("red")
})
.red {
  color: red;
}
<h1>Stackoverflow is nice!</h1>
<p>Great website!</p>
<button>Change CSS</button>

  • Create a button which listens for a user action.
  • When the button is clicked add a class to the body element.
  • Use this class to apply different css rules.

You can build a dark theme with that for example.

about 4 years ago · Santiago Gelvez Report

0

As previously said by @Lain, it is indeed possible. something like someElement.classList.add() or someElement.classlist.toggle() MDN Web API

about 4 years ago · Santiago Gelvez 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!