0
votes

Say i have 4 div's in an enclosing div. The div's inside have classes of div1, div2, div3, div4.

I want to save the order of these div's and then load the correct order the next time the page loads. (e.g. http://jquery-howto.blogspot.com/2010/09/jquery-cookies-getsetdelete-plugin.html)

So. My question is. What is the best way to turn this list of divs into an array to be stored in a cookie?

Code snippets would be appreciated.

Thanks

1
You just want to save the orders, not the content? Can't you just extract the ordered list of class names and save that as a string? - Rup
I was planning on saving just the orders, and then when the page loads again later using jQuery to order them properly. Would you be able to show some example code? - Undefined

1 Answers

1
votes

Something like:

var order = [];
$('#containerDiv').children().each(function() {
    order.push($(this).attr('class'));
});
var orderString = order.join(","); // this will be div1,div2,div3 etc..