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

197
Views
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 answers
Answer question

0

Are you trying to make an accordion menu?

You can show-hide with trigger

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!