jQuery toggle caching / cookies
Posted
by
user1706680
on Stack Overflow
See other posts from Stack Overflow
or by user1706680
Published on 2012-11-03T22:57:39Z
Indexed on
2012/11/03
23:00 UTC
Read the original article
Hit count: 232
I’m using the jQuery toggle function for my navigation. By default the Authors toggle is visible, the Archives toggle is closed.
My problem is that when the users switches to another page the toggles reset themselves.
For example, when the user closes the Authors toggle and opens the Archive toggle and then navigates to another page the default settings are loaded.
I read that it’s possible to store the settings via cookies but I’m absolutely new to jQuery and it would be great if somebody could help me out!
HTML
<div id="authors" class="widget">
<h2 class="widget-title-visible">Authors</h2>
<div class="toggle">
<div class="submenu">
<ul>
<li>Name 1</li>
<li>Name 2</li>
<li>Name 3</li>
<li>Name 3</li>
</ul>
</div>
</div>
<div id="archives" class="widget">
<h2 class="widget-title">Archiv</h2>
<div class="toggle hidden">
<div class="submenu">
<ul>
<li>November 2012</li>
<li>Oktober 2012</li>
</ul>
</div>
</div>
</div>?
jQuery
function toggleWidgets() {
jQuery('.widget-title').addClass('plus');
jQuery('.widget-title-visible').addClass('minus');
jQuery('.widget-title').click(function() {
$(this).toggleClass('plus').toggleClass('minus').next().toggle(180);
});
jQuery('.widget-title-visible').click(function() {
$(this).toggleClass('minus').toggleClass('plus').next().toggle(180);
});
}
jQuery(document).ready(function() {
toggleWidgets();
} )?
CSS
.hidden{
display:none;
}
.plus {
background: url(http://moargh.de/daten/sidebar_arrows.png) 0 5px no-repeat;
padding: 0 0 0 12px;
}
.minus {
background: url(http://moargh.de/daten/sidebar_arrows.png) 0 -10px no-repeat;
padding: 0 0 0 12px;
}
?
© Stack Overflow or respective owner