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

196
Views
Keep innerhtml updated after page reload jQuery

I have a jQuery which looked for clicked event and change the innerhtml according clicked element. But the issue is when page gets reload it remove the updated html and bring back the initial html. I tried to use localstorage function. Not sure using correctly this.

HTML

<nav class="woocommerce-MyAccount-navigation dropdown">
   <a href="#" class="js-link">Dashboard <i class="fa fa-chevron-down"></i></a>
    <ul class="js-dropdown-list">
                  <li class="woocommerce-MyAccount-navigation-link woocommerce-MyAccount-navigation-link--dashboard">
                <a href="https://www.example.com/mijn-account/">Dashboard</a>
            </li>
                  <li class="woocommerce-MyAccount-navigation-link woocommerce-MyAccount-navigation-link--edit-account">
                <a href="https://www.example.com/mijn-account/edit-account/">Mijn Gegevens</a>
            </li>
                  <li class="woocommerce-MyAccount-navigation-link woocommerce-MyAccount-navigation-link--wishlist">
                <a href="https://www.example.com/verlanglijst/?wishlist-action">Verlanglijst</a>
            </li>
                  <li class="woocommerce-MyAccount-navigation-link woocommerce-MyAccount-navigation-link--edit-address">
                <a href="https://www.example.com/mijn-account/edit-address/">Mijn Adressen</a>
            </li>
   </ul>
</nav>

I want to update innerhtml of .js-link element. Like when click on Mijn gegevens it should be "Mijn gegevens" instead of Dashboard.

JS

jQuery(function() {
  var list = jQuery('.js-dropdown-list');
  var link = jQuery('.js-link');
  link.click(function(e) {
    //e.preventDefault();
    list.slideToggle(200);
  });
  list.find('li').click(function() {
    if (jQuery(this).attr('class') == localStorage.getItem("Activeli")) {
      var text = jQuery(this).html();
      var icon = '<i class="fa fa-chevron-down"></i>';
      link.html(text+icon);
      list.slideToggle(200);
    }
    var id = jQuery(".woocommerce-MyAccount-navigation-link").attr("class");
      localStorage.setItem("Activeli", id); //create a localstorage
  });
});

Can someone help how can i achieve this?

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
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!