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

265
Views
How to change loading state button with JS?

I am redirecting to another page with anchor tag and when the button is clicked I use some javascript to show loading spinner inside the button:

//Example
const a = document.getElementById("some_id");
a.innerHTML = //here I place some divs to show the spinner

My problem is that when I try it on mobile the button is changing its state and redirecting, but when I hit back and go back to the same page, the state is persisted and the button is still in loading state.

I tried using some lifecycle hooks like "beforeunload", "unload" to change the button then, but it's not working. I have also tried to use

document.addEventListener("DOMContentLoaded", function() {//some code to bring back state})

but I still don't have success. This is not a problem on desktop. But on mobile it's acting like SPA and when I hit back the state is persisted...

about 4 years ago · Santiago Trujillo
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!