Currently, I am developing a left sidebar menu that expands and collapses upon clicking a button.
I need to find a way to save the state of the menu, whether it is expanded or collapsed, so that when the page is refreshed, the same class will still be applied.
$('#menu-action').click(function() {
$('.sidebar').toggleClass('active');
$('.main').toggleClass('active');
$(this).toggleClass('active');
if ($('.sidebar').hasClass('active')) {
$(this).find('i').addClass('fa-close');
$(this).find('i').removeClass('fa-bars');
} else {
$(this).find('i').addClass('fa-bars');
$(this).find('i').removeClass('fa-close');
}
});
// Provide hover effect for the menu
$('#menu-action').hover(function() {
$('.sidebar').toggleClass('hovered');
});