Posted By

phil7085 on 06/26/10


Tagged

show plugin html cookie hide jquery


Versions (?)

Advanced use of jQuery cookie plugin to show/hide a notice, includes changing the HTML text of the link


 / Published in: JavaScript
 

  1. $(document).ready(function() {
  2.  
  3. if ($.cookie('notice') == 'closed') {
  4. $('a.toggle').html('Open the notice');
  5. $('.notice').hide();
  6. } else {
  7. $('.notice').show();
  8. }
  9. // Show or hide on load depending on cookie
  10.  
  11. $('a.toggle').click(function(e) {
  12. e.preventDefault()
  13. if ($.cookie('notice') == 'closed') {
  14. $('.notice').show();
  15. $('a.toggle').html('Close the notice');
  16. $.cookie('notice','open');
  17. } else {
  18. $('.notice').hide();
  19. $('a.toggle').html('Open the notice');
  20. $.cookie('notice','closed');
  21. }
  22. });
  23. // a more advanced link, this time to toggle the notice
  24.  
  25. });
  26.  

Report this snippet  

You need to login to post a comment.