0

Most of the answers I've checked suggest using a plugin, but to save me editing 100+ pages of my site by adding a plugin URL into the headers, I'm asking if it's possible to do the following without a plugin...

I have a menu with several submenus that are toggled to show/hide using jquery. I want to save a cookie so the menu status is saved between page loads.

Current code example:

$('#heading1').click(function() {
$('#menu1').toggle( "fast" );
});

$('#heading2').click(function() {
$('#menu2').toggle( "fast" );
});

If it's not possible/easy then I'll go for the plugin

Jamal Lanten
  • 69
  • 1
  • 11
  • Your 100+ pages of your site should share a common header (template). Regarding your issue: http://stackoverflow.com/questions/14573223/set-cookie-and-get-cookie-with-javascript – A. Wolff Feb 25 '14 at 14:59

2 Answers2

0

You can also just past the plugin code above these lines? Or at the bottom of that file. Because the plugin is nothing more than a few lines of code. You can make it custom but than you are spending more time.

Add the plugin to the top of the file. And use cookies.

Niels
  • 48,601
  • 4
  • 62
  • 81
0

The default JavaScript "API" for setting a cookie is as easy as:

document.cookie = 'mycookie=valueOfCookie;expires=DateHere;path=/'

Find a link here

Community
  • 1
  • 1
Jimba Tamang
  • 1,275
  • 15
  • 17