Rainieren
1 year ago

jQuery save toggleClass in localStorage

Posted 1 year ago by Rainieren

Hello, I made a sidebar and I want to save the status of the sidebar for users. If they choose to pick the "Collapsed" version of the sidebar, If they refresh the page the sidebar still stays that way. I know I can use localStorage with this but I don't know how.

Code

$(document).ready(function() {

    $('#sidebar-toggler').on('click', function() {
        $('#sidebar').toggleClass('active');
        $('#navbar-brand').toggleClass('active');
        $('#content').toggleClass('active');
    });

});

How can I achieve the above? Thanks in advance

Please sign in or create an account to participate in this conversation.