I have problems with cookies

I have problems with cookies

Hello everyone!!!

I'm starting with jQuery and specially with cookies. As a test application I'm using a nested list with a collapsible effect created with jQuery.

The effect is working fine and now I'm trying the next level which is save the state of the list between reloads. For this I'm using cookies (jquery.cookie.js) but there is something strange that I can't understand. 

The cookie is been saved in the browser but I can't get the value after reloading the page. 




This is how my code looks like:

  1. <script type="text/javascript">
  2. $(document).ready(function() {
  3. $('ul li').children('ul').hide();
  4. var c = $.cookie(this.id);
  5. if(c === 'true') {
  6. console.log(c);
  7. alert('Value');
  8. } else {
  9. alert('no Value');
  10. }
  11. $('ul li').addClass('reveal');
  12. $('.reveal').each(function(i) {
  13. $(this).attr('id', 'li'+i++);
  14. });
  15. $('.reveal').click(function() {
  16. $(this).children('ul').slideDown();
  17. $.cookie(this.id, 'true');
  18. console.log($.cookie(this.id));
  19. });
  20. });
  21. </script>
  22. </head>
  23. <body>
  24. <ul>
  25. <li>
  26. <span>Header</span>
  27. <ul>
  28. <li><a href="page2.html">Page 2</a></li>
  29. <li>No link</li>
  30. <li><a href="page2.html">Page 2</a></li>
  31. </ul>
  32. </li>
  33. <li>Header</li>
  34. <li>Header</li>
  35. <li>
  36. <span>Header</span>
  37. <ul>
  38. <li><a href="page2.html">Page 2</a></li>
  39. <li>
  40. <span>Header</span>
  41. <ul>
  42. <li><a href="page2.html">Page 2</a></li>
  43. <li>No link</li>
  44. <li><a href="page2.html">Page 2</a></li>
  45. </ul>
  46. </li>
  47. <li><a href="page2.html">Page 2</a></li>
  48. </ul>
  49. </li>
  50. </ul>
  51. </body>
      Of course I'm calling jQuery and jquery.cookies.js in the head before the $(document).ready 
What I'm doing wrong? 

Thanks for your help!!!