Answer the question
In order to leave comments, you need to log in
Why can't cookies work in Bootstrap collapse?
Hello. Friends, do not tell me why cookies may not work in collapse. I found a working example on jsfiddle, it is under Bootstrap 2.3.2, I use 3.2.0 and does not want to work. None.
Looks like that:
<button class="btn btn-danger" data-toggle="collapse" data-target="#demo">simple collapsible</button>
<div id="demo" class="collapse in">
<img src="//placehold.it/400x200">
</div>
$( document ).ready(function() {
var c = document.cookie;
$('.collapse').each(function () {
if (this.id) {
var pos = c.indexOf(this.id + "_collapse_in=");
if (pos > -1) {
c.substr(pos).split('=')[1].indexOf('false') ? $(this).addClass('in') : $(this).removeClass('in');
}
}
}).on('hidden shown', function () {
if (this.id) {
document.cookie = this.id + "_collapse_in=" + $(this).hasClass('in');
}
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question