A bit of a js/jquery novice - I'm using Bootstrap and data-toggle + collapse classes to show/hide divs. I've been scouring the 'net trying to find something that will maintain the state of all divs, whether identified by a unique ID or a CLASS, between page refreshes. I've seen discussions on cookies and local storage, I don't think I care which method is used (although I've had errors with $.cookie is not a function, so maybe local storage is better?).
The issue is most examples deal with maintaining accordion states, which I don't think exactly apply here. I've tried modifying various code examples but they just don't quite seem to work.
Here is an example of my code:
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<div class="panel panel-danger">
<div data-toggle="collapse" href="#duesoon" style="cursor: pointer;" class="panel-heading">
<font class="panel-title"><span class='glyphicon glyphicon-fire'></span> Top 5 Expiring Tasks</font>
</div>
<div id="duesoon" class="collapse">
<table class="table table-hover table-striped table-condensed">
<thead>
<tr>
<th class='col-md-7'>Name</th>
<th class='col-md-5'>End Date</th>
</tr>
</thead>
<tbody>
<tr style="cursor: pointer;" onclick="document.location = '?action=view&type=project&id=2">
<td><span class='glyphicon glyphicon-triangle-right'></span> Take Out The Trash</td>
<td>Yesterday</td>
</tr>
</tbody>
</table>
</div>
<div data-toggle="collapse" href="#urgency" style="cursor: pointer;" class="panel-heading">
<font class="panel-title"><span class='glyphicon glyphicon-fire'></span> Top 5 Urgent Tasks</font>
</div>
<div id="urgency" class="collapse">
<table class="table table-hover table-striped table-condensed">
<thead>
<tr>
<th class='col-md-7'>Name</th>
<th class='col-md-5'>Priority</th>
</tr>
</thead>
<tbody>
<tr style="cursor: pointer;" onclick="document.location = '?action=view&type=project&id=1">
<td><span class='glyphicon glyphicon-triangle-right'></span> Save the Whales</td>
<td>Critical</td>
</tr>
</tbody>
</table>
</div>
</div>
As you can see, there's a link or a button or something that toggles showing/hiding a div.
Same thing on JSFiddle: http://jsfiddle.net/w8psgvaa/2/
I found this code example;
$('.collapse').on('hidden', function() {
// store this.id
}).on('shown', function() {
// delete this.id
});
$(document).ready(function(){
$(".collapse").collapse().each(function(){
if( isStored( this.id ) ) {
$( this ).collapse( 'hide' );
}
});
});
But unfortunately it's incomplete. and some divs start out collapsed (as in my example). Any help is appreciated!