keep the data-toggle of an icon for the other pages (how to get the data-toggle of an icon and share the last change with other pages)

Viewed 24

I work with php

I have this:

<i id="imicon" data-toggle="collapsed" class="ft-circle toggle-icon"></i>

when you click in this icon, the data-toggle will be changed to 'expanded'; I have this icon in another pages

In general, when you open one page that includes this icon, it is collapsed! But I want this: For example, in the first page, I have clicked on this icon and it is expanded now; When I open the second page, still, I want it to be expanded!

with clicking on the icon, data-toggle will be 'expanded' and class will be 'ft-disc ...'

Please help me how to keep the last changes and use them in other pages

1 Answers

you can use the localStorage object to save some parameter for the current status in the browser.

try this :

$(document).ready(function(){
$('a[data-toggle="tab"]').on('show.bs.tab', function(e) {
    localStorage.setItem('activeTab', $(e.target).attr('href'));
});
var activeTab = localStorage.getItem('activeTab');
if(activeTab){
    $('#myTab a[href="' + activeTab + '"]').tab('show');
}});
Related