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

168
Views
Los estilos se revierten después de cambiarse con el código JS

Estoy tratando de establecer los estilos de un div cuando se hace clic en un botón. Los cambios ocurren, pero luego vuelven instantáneamente al estilo existente.

Ver demostración

Código fuente completo

 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/

Cambiar a

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

después

 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!