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

187
Views
Change a particular class background color on another div click

I want to change the background color of a div on click of another div. I tried this

HTML

<div class="post-main-content">
    <br /><hr />
    <p>
    <br />
    Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequuntur, 
    iusto quasi eum, delectus, soluta aliquam modi suscipit non fuga fugiat 
    nemo ullam eos? Eaque soluta esse, dolore voluptates vitae sunt 
    recusandae libero provident accusantium ex nemo quaerat quidem cumque 
    corrupti voluptatibus cum debitis assumenda sequi veniam corporis quam 
    <p>
</div>

JavaScript

const backChange = document.querySelector('post-main-content').addEventListener("click", function(e){
    e.backChange.style.background = "black"
})

Still didn't work.

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

0

add a dot in querySelector

const backChange = document.querySelector('.post-main-content');
backChange.addEventListener("click", function(){
    backChange.style.background = "black";
});
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!