Increment variable for

Posted by John Doe on Stack Overflow See other posts from Stack Overflow or by John Doe
Published on 2010-04-25T00:24:57Z Indexed on 2010/04/25 0:33 UTC
Read the original article Hit count: 559

Filed under:
|
|
|
|

Hello. I have 30 divs with the same class on the same page. When i'm pressing the title (.pull) the content is sliding up (.toggle_container). When the content is hidden and i'm pressing the title again, the content is sliding down. Also, i want to store the div state inside a cookie. I modified my original code to store the div state inside a cookie but it's not working for all the divs (pull1, toggle_container1, pull2, toggle_container2 [...]), it's working only for the first one (pull0, toggle_container0). What i'm doing wrong?

var increment = 0;
           if ($.cookie('showTop') == 'collapsed') {
               $(".toggle_container" + increment).hide();
            }else {
               $(".toggle_container" + increment).show();
         };
          $("a.pull" + increment).click(function () {
            if ($(".toggle_container" + increment).is(":hidden")) {
               $(".toggle_container" + increment).slideDown("slow");
               $.cookie('showTop', 'expanded');
               increment++;
            } else {
               $(".toggle_container" + increment).slideUp("slow");
               $.cookie('showTop', 'collapsed');
               increment++;
            }
            return false;

          });    

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about html