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

214
Views
click button (CSS) using JS script

Im making a simon says game, i use 4 colored buttons that works perfectly. the process is simple- the program present the user with the colors. the repeat the sequence by clicking the buttons.

I wish to let the program activate the button the same way a user would, with the appropriate activate effect.

.but:active{ // <-- how do i initiate this with js?
        box-shadow: 0 5px #666;
        transform: translateY(4px);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You mean

document.querySelector(".but").click()

or

const buts = document.querySelectorAll(".but");
const cnt = 0;
setInterval(function() { 
  if (cnt>= 0) cnt = 0; 
  but[cnt].click();
  cnt++;
},2000)
about 4 years ago · Juan Pablo Isaza Report

0

let but = document.querySelector('.but');

but.addEventListener('click', () => {
   but.classList.add('active');

   let activeStatus = document.querySelector('.active');
   activeStatus.style = `
   box-shadow: 0 5px #666;
   transform: translateY(4px);
  `;
});
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!