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

199
Vistas
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 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