change from list to grid [closed]

0

I have a big doubt that there are many asking the same thing but I do not find anything clear on the internet, I want to know how to change the list / grid, in my products, for now I have this:

<script>
    $('button').on('click',function(e) {
    if ($(this).hasClass('grid')) {
        $('#container div').removeClass('list').addClass('grid');

    }else
        if($(this).hasClass('list')) {
        $('#container div').removeClass('grid').addClass('list');
    }
});</script>

when you change the page, it takes the initial value again, (squares) and I want it to be with the class selected by the user. Thanks for the support, I'm really lost.

    
asked by ALVARO JAVIER MEJIA HENAO 18.04.2017 в 16:52
source

1 answer

1

As you know JavaScript is not a language that acts on server, only on the client, so to make these changes the normal thing (I think) is to save the value you want to keep in a cookie that is saved in the client's browser , this is explained very well here The summary would be something like this:

var valorAGuardar= "value";
localStorage.setItem("NombreVariable", valorAGuardar);

At this point we have created the cookie and can access it at any time as follows:

var nombreVariable= localStorage.getItem("NombreVariable");

This variable nombreVariable will always return or null (if no value has been initialized in the cookie) or the value saved previously.

    
answered by 18.04.2017 в 17:13