im still fairly new to jquery and i got this slideToggle container,
but now i want to save a cookie if the container is hidden or not so
if one refreshes the page it keeps its current state.
I heard about the jquery cookie plugin but didn’t really understand it to be honest. 🙁
Can anyone help me out?
My code so far is pretty simple:
$(function(){
$("#hideslide").click(function(){
$(this).next().slideToggle();
});
});
Any help is highly appreciated
The jQuery Cookie plugin (found here) is the easiest way to use cookies with jQuery.
To set a cookie, this will do:
Getting a cookie is just as simple:
So you should check on page load if the cookie is set:
And on clicking the item to toggle, check if cookie is set. If it is set, remove it, else, set it:
I use this plugin myself and this is all you need. Easy.