javascript - How to keep toogleClass() state on page refresh or moving to another HTML subsite? -
i have page couple subpages in .html. on every page there 2 "buttons" language change. there solution, me keep selected language after page refresh or moving subsite?
this code:
// language icons // var polico = $('.language_ico_container').find('img').first(); var engico = $('.language_ico_container').find('img').last(); engico.toggleclass('transparency'); function checktransparency() { engico.click(function () { $(this).toggleclass('transparency'); if (engico.hasclass('transparency')) { polico.removeclass('transparency'); } else { polico.addclass('transparency'); } }); polico.click(function () { $(this).toggleclass('transparency'); if (polico.hasclass('transparency')) { engico.removeclass('transparency'); } else { engico.addclass('transparency'); } }); }; // call function checking transparency in language icons // checktransparency(); // english & polish content selection // var languagepl = $('.pl'); var languageen = $('.eng'); languageen.toggleclass('hidden'); function changelanguage() { engico.click(function () { languageen.toggleclass('hidden'); languagepl.toggleclass('hidden'); }); polico.click(function () { languageen.toggleclass('hidden'); languagepl.toggleclass('hidden'); }); }; // call function changing content language changelanguage();
and css classes:
.hidden { display: none; } .transparency { opacity: 0.5; }
localstorage can solution used save data across browser sessions.. can implement classes session storage, every time set transparency class can add local storage.
localstorage.setitem('class','transparency');
when remove class can remove local storage
localstorage.removeitem('class');
and when page refreshed can set class localstorage
localstorage.getitem('class');
Comments
Post a Comment