1

Possible Duplicate:
What is the “best” way to get and set a single cookie value using JavaScript

I made a notification bar which you can see at the top of the site. There is a p tag with the text "close x" in it which when clicked will add a class to the container using jquery and hide the bar. What I am trying to do though is create a cookie for the user when they click this so that the choice to hide the bar is saved until they end their session on the site.

I really don't know much about setting up cookies, any ideas?

Here is the live version to see: http://www.brainbuzzmedia.com/themes/simplybusiness/

Community
  • 1
  • 1
BRAINBUZZ media
  • 494
  • 3
  • 9
  • 25

1 Answers1

3

Use jQuery -Cookie plugin

SET COOKIE

$.cookie('SampleKey', 'SampleValue', { path: '/' });

GET COOKIE

$.cookie('SampleKey');

I assume you have a div where you want to write the text 'Closed' UPDATE

HTML

<div id="close"></div>

JS

if($.cookie('CookieKey')=='closed'){
    $("#close").html('Closed');
}
Tariqulazam
  • 4,535
  • 1
  • 34
  • 42