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

183
Views
Styles revert back after being changed with JS code

I am trying to set the styles of a div when a button is clicked. The changes occur but then they instantly revert back to the existing styling.

View Demo

Full Source Code

document.body.addEventListener("click", (e) => {
  if (e.target.classList.contains("js-multi-btn")) {
    gameBoard.setGameMode('multi');
    displayController.revealBoard();
  }
});

document.body.addEventListener("click", (e) => {
  if (e.target.classList.contains("js-single-btn")) {
    gameBoard.setGameMode('single');
    displayController.revealBoard();
  }
});

function revealBoard() {
  var btns = document.querySelector('.js-gameplay-btns');
  btns.style.display = 'none'
  var board = document.getElementById('js-board')
  board.style.backgroundColor = 'white';
}
<a href="" class="js-multi-btn multi-btn">Multi Player Mode</a>
<a href="" class="js-single-btn single-btn">Single Player Mode</a>

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

0

https://jsfiddle.net/mplungjan/unjsp6tm/

Change to

   <a href="" data-gm="multi" class="js-btn single-btn">
   <a href="" data-gm="single" class="js-btn multi-btn">

then

document.querySelector(".js-gameplay-btns").addEventListener("click", (e) => {
  const tgt = e.target.closest("a");
  if (tgt && tgt.classList.contains("js-btn")) {
    e.preventDefault()
    gameBoard.setGameMode(tgt.dataset.gm);
    displayController.revealBoard();
  }
})
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!