Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
CSS/JavaScript code works when implemented, but when I refresh the page it doesn't work

I am using the HTML widget for Elementor, a Wordpress theme builder. I am trying to show/hide sections (sect1 - sect12 named HTML, CSS, Javascript and Node) when I click on certain buttons (btn1, btn2, btn3, named Frontend Developer, Backend Developer and Designer), and I got it to work, but when I refresh the page the buttons become unclickable. Each button controls 4 sections, so btn1 -> sect1 - sect4, btn2 -> sect5 - sect8, btn3 -> sect9 - sect 12.

<script>
.elementor-editor-active .hidden{
  display:block;
}
.hidden{
  display:none;
}
.shown{
  display: block !important;
  animation: fade_in_anim 0.5s;
}
.btn_active_state{
  background-color: #D9D3FF !important;
}
@keyframes fade_in_anim {
  0% {
    opacity: 0;
    transform: translateY(-30px);
  }
  100% {
    opacity: 1;
    transform: translateY(0px);
  }
}
const buttons = [...document.querySelectorAll("[id^='btn']")]
const mapping = [[0, 4], [4, 8], [8,12]]
const sections = [...document.querySelectorAll("[id^='sect']")]

for(let i = 0; i < 3; i++) {
  buttons[i].addEventListener('click', function(event) {
    event.preventDefault();
    toggleDivs(this)
    for(let j = mapping[i][0]; j < mapping[i][1]; j++) {
      sections[j].classList.add("shown", "fade")
    }
  })
}

function toggleDivs(btn){
  buttons.forEach(b => b.classList.remove("btn_active_state"))
  btn.classList.add("btn_active_state")
  sections.forEach(s => s.classList.remove('shown'))
}

//force button1 state initialise, if required
btn1.focus();
btn1.click();
</script>
<style>
.elementor-editor-active .hidden{
  display:block;
}
.hidden{
  display:none;
}
.shown{
  display: block !important;
  animation: fade_in_anim 0.5s;
}
.btn_active_state{
  background-color: #D9D3FF !important;
}
@keyframes fade_in_anim {
  0% {
    opacity: 0;
    transform: translateY(-30px);
  }
  100% {
    opacity: 1;
    transform: translateY(0px);
  }
}
</style>

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Are you trying to make an accordion menu?

You can show-hide with trigger

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda