views:

26

answers:

2

Hey guys, I really can't figure out how to use cookies with this class switcher I got here

Jquery:

<script type="text/javascript">

    $(document).ready(function(){

    $("a.switch_thumb").toggle(function(){
        $(this).addClass("swap");
        $(".main").fadeOut("fast", function() {
            $(this).fadeIn(300).addClass("main2");
        });
    }, function () {
        $(this).addClass("swap");
        $(".main2").fadeOut("fast", function() {
            $(this).fadeIn(300).addClass("main3");
        });

    }, function () {
        $(this).removeClass("swap");
        $(".main").fadeOut("fast", function() {
            $(this).fadeIn(300).removeClass("main3");
    $(this).fadeIn(300).removeClass("main2");
        });
    });

</script>

Any tips?

A: 

It's not really clear what you're trying to do here without a link to the page; I'd suggest restructuring the code to be a single function called via the click method.

You can then call that function on document ready too switching on the cookie which you could set with the jQuery Cookie Plugin; therefore maintaining the current selection across different pages which I think is your intended functionality?

Steve
A: 

It's a script that flips between 3 views (3 different backgrounds) and I want it to remember the last chosen background

sandro
Is it understandable now? :)
sandro
This should be a comment not an answer.
Steve