Earlier today i asked a question on here, but didnt explained it properly and havent provided proper code.
I have 2 toggle DIVs with links in them, and once user opens one and clicks on the link, page refresh with results, but that DIV closes itself. I would like it to remain open.
$(document).ready(function() {
$(".content").hide();
$(".fa-angle-double-up").hide();
$(".heading").click(function(){
$(this).next(".content").slideToggle(500);
$(this).find(".fa-angle-double-up, .fa-angle-double-down").toggle();
});
});
Somebody told me that it can be done either by setting cookies or by storing it into localstorage, but i have no idea (JS newbie).If anybody can help, you would save my day :)
Fiddle: http://jsfiddle.net/eg7ju4rm/
Moderators, if it is against the rules to post 2 questions with the same topic, i apologize
In your click-event you can add this:
to save the
ID
of the opened section. And add this to your ready-handler:Demo
I don't know if only one div should be stay open or every opend div, my solutions just handle one open div.
You can indeed store references to the expanded elements in the
localStorage
(or perhapssessionStorage
could be more appropriate), and upon page load, restore their state:Fiddle
Also, see DOM Storage