Simple use of jQuery cookie plugin to show/hide a notice


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $(document).ready(function() {
  2.  
  3. if ($.cookie('notice') == 'closed') {
  4. $('.notice').hide();
  5. } else {
  6. $('.notice').show();
  7. }
  8. // Show or hide on load depending on cookie
  9.  
  10. $('.notice a.close').click(function(e) {
  11. e.preventDefault();
  12. $.cookie('notice','closed');
  13. $(this).parent().hide();
  14. });
  15. // Simple close link to hide the notice until cookies are cleared
  16.  
  17. $('a.open').click(function(e) {
  18. e.preventDefault();
  19. $.cookie('notice','open');
  20. $('.notice').show();
  21. });
  22. // Opener link to show the notice again
  23.  
  24. });
  25.  

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.