multiple "collapsable <div>'s" in cookie

multiple "collapsable <div>'s" in cookie

  1. if($.cookie("panelState") == undefined) {
  2. $.cookie("panelState", "collapsed");
  3. }
  4. var state = $.cookie("panelState");
  5. if(state == "collapsed") {
  6. $(".toggle_container").hide(); 
  7. }
  8. $("h2.trigger").click(function(){
  9. if($.cookie("panelState") == "expanded") {
  10. $.cookie("panelState", "collapsed");

  11. } else {
  12. $.cookie("panelState", "expanded");
  13. }
  14. $(this).toggleClass("active").next().slideToggle("slow");
  15. return false; //Prevent the browser jump to the link anchor
  16. });
  17. });

Hello,

I use jquery for hiding/collapsing a <div>-tag. Now I want to save the state of the panel in a cookie. (so the state is still the same after reloading the page) (cookie-plugin)
My problem is, that I have more than one "collapsable <div>-tags" on the same page. How can I modify my code, so that it works for each of my "collabsable boxes"? (the state of each one has to be stored in a cookie separately!)

Thanks!!
Léo
    • Topic Participants

    • info