I'm making a jquery plugin to create 'spindowns', you can locate the project at http://github.com/c00lryguy/jquery.spindown.js

The problem is the only way I could figure out how to save which elements were expanded was to save an array filled with the expanded elements inner text.

Now, there are obvious downfalls to this. For instance, if two elements have the same text and one is expanded and the other wasn't, when it loads it from a cookie, it will think both of them were expanded.

Is there a good way to save an array of elements to a cookie?

Example


$('.expandable').spindown();

<div class="expandable">First spindown</div>
<div>Content</div>
<ul>
    <li class="expandable">Second spindown</div>
    <img src="someimg.jpg"></img>
</ul>

Now, when a user clicks the div containing "First spindown", the div containing "Content" would slide down. And when a user clicks the li containing "Second spindown", the img element underneath it would slide down, kinda like an accordion.

This is because it finds the element with the "expandable" class and makes it clickable, toggling the slide effect for the next logical element.

1 answer

danwellman 5600
0
points

The jQuery cookie plugin is awesome :)

Not sure if you can save an array, but you can save a series of name:value pairs so it should be easy to create a state-saving mechanism using unique ids and an expanded/contracted value...

Answered over 9 years ago by danwellman