3
3
3axapV2015-02-19 16:24:39
HTTP Cookies
3axapV, 2015-02-19 16:24:39

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');
    }
});
});

It works here, I'm transferring it to the template under Bootstrap 3.2.0 - It doesn't work .. I'll never know.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Romanov, 2015-08-16
@evanto

In the example, the Bootstrap version is v2.0.4

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question