Hello to all! localStorage.setItem does not work I can not understand the reason. When clicked, everything works, but after the update in the browser, all classes disappear, but should have been saved. thank

 // Product Grid $('#grid-view').click(function() { // What a shame bootstrap does not take into account dynamically loaded columns $('#content .list-product').attr('class', 'col-md-4 col-sm-6 product_main grid-product'); $('#list-view').removeClass('active'); $('#grid-view').addClass('active'); localStorage.setItem('display', 'list'); }); if (localStorage.getItem('display') == 'list') { $('#list-view').trigger('click'); $('#list-view').addClass('active'); } else { $('#grid-view').trigger('click'); $('#grid-view').addClass('active'); } // Product List $('#list-view').click(function() { //$('#content .product-grid > .clearfix').remove(); $('#content .row > .grid-product').attr('class', 'col-md-12 product_main list-product'); $('#grid-view').removeClass('active'); $('#list-view').addClass('active'); localStorage.setItem('display', 'list'); }); 
  • check that these elements already exist in the DOM at the time of the check. It may be worth putting the check in $(function(){...}) if it is not there yet, or before the closing body tag - Grundy
  • Well, put if (localStorage.getItem('display') == 'list') { ... after both $(...).click(function() { ... - Igor

0