-3

Hello been looking around online for this for awhile and would really appreciate some help please. I need to know what script that invloves cookies can keep a toggled div in the below code in a "CLICKED" state after the page reloads. Appreciate all and anyones help and give much thanks in advanced.

<!DOCTYPE html>
<html>
<head>
  <style>
      p.one { position:relative; width:400px; height:90px; }
      div.two { position:relative; width:400px; height:65px; 
        font-size:36px; text-align:center; 
        color:yellow; background:red;
        padding-top:25px; 
        top:0; left:0; display:none; }
        span.three { display:none; }
      </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>


</head>
<body>
  <p class="one">
        Let it be known that the party of the first part
        and the party of the second part are henceforth
        and hereto directed to assess the allegations
        for factual correctness... 



 <input type="button" id="toggle_button" value="TEST" />


</div>
        <div id="two" class="two"><span id=''three' class="three">Click here to continue...</span></div>

      </p>
<script>
        $('#toggle_button').click(function () {
          $("#two").fadeIn(3000, function () {
            $("#three").fadeIn(100);
          });
          return false;
        }); 

      </script>

      </body>
      </html>

How could i get somthing like the below to work with my code?

 <script type="text/javascript">

    $(function() {

        var cookie = document.cookie,
            state  = cookie.substr(cookie.search('buttonCollapsed=')+16,1),
            elem   = $('div.collapsable');

        if (state == 1) {
            elem.hide();
        }

        elem.slideToogle(function() {

            if ( elem.is(':visible') ) {
                document.cookie = "toggle_button=0";
            } else {
                document.cookie = "toggle_button=1";
            }

        });

    });
    </script>
user1824806
  • 65
  • 1
  • 2
  • 8

1 Answers1

0

You can see how to use cookie with jQuery in here sorry cookie page of jQuery website doesn t response right now.

What you should do id set the the cookie on every click event;

$.cookie("lastOne", this.id);

and on document ready function check if the cookie exists and open the given id;

$(document).ready(function () {
      if ($.cookie("lastOne") != null)
          $("#" + $.cookie("lastOne")).click();
});

that should do the trick.

Community
  • 1
  • 1
Onur Topal
  • 3,042
  • 1
  • 24
  • 41