Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

197
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda