0

I've got a button that switches between grid view and list view, the script is able to switch the styling no problem but when going to page 2 (pagination) the view returns back to list view. How can I get the views to remain when using pagination? Here is my JS script. I can also provide more info if asked.

    $('button').click(function(e) {
     if ($(this).hasClass('grid')) {
            $('#container ul').removeClass('list').addClass('auto-grid');
         }

         else if($(this).hasClass('list')) {
            $('#container ul').removeClass('auto-grid').addClass('list');
          }

    });
mario009
  • 41
  • 7
  • What does "going to page 2" involve? If you're navigating to an entirely new page (even if it's the same URL) then you're starting over from scratch. You'd need to store this information somewhere (e.g. `localStorage`) and read it when the page loads. – David Sep 27 '22 at 14:20
  • Yeah its navigating to a new page, any tips on how to store it using localStorage? – mario009 Sep 27 '22 at 14:22
  • You can start with tutorials and examples on using [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage). Your favorite search engine can help find those. – David Sep 27 '22 at 14:23
  • Does this answer your question? [Persist variables between page loads](https://stackoverflow.com/questions/29986657/persist-variables-between-page-loads) – Don't Panic Sep 28 '22 at 08:59

0 Answers0