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.