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

112
Views
change color with click on js

i want change the color of this div when i click on it i try to use this javascript but nothing,

const buttonChange = () => {

  const button = document.querySelector('.uno');
  button.addEventListener('click', () => {
    button.classList.toggle('.uno-active');
  })



}
.uno{
color: rgb(12, 114, 231);
background-color: rgb(255, 255, 255);
}
.uno-active{
    color: rgb(255, 255, 255);
    background-color: rgb(11, 28, 47);;
    
}
<div>
            <p class="uno">COSA È</p>
  </div>

////////////////////////////////

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

0

You have to call the buttonChange() function if you want to handle the click event. Also you don't have to put a dot before "uno-active" :

const buttonChange = () => {
  const button = document.querySelector('.uno');
  button.addEventListener('click', () => {
    button.classList.toggle('uno-active');
  });
}
buttonChange();
.uno{
  color: rgb(12, 114, 231);
  background-color: rgb(255, 255, 255);
}

.uno-active{
  color: rgb(255, 255, 255);
  background-color: rgb(11, 28, 47);
}
<div>
  <p class="uno">COSA È</p>
</div>

about 4 years ago · Juan Pablo Isaza Report

0

Use <div id="yourID" onclick="javascript:yourFunction();"></div> for calling the right JS/Jquery function and use function myFunction() { document.getElementById("yourID").style.background = "#000"; } to give the style.

Here is aJSfiddle.

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!