I had the same problem, so I looked into bootstrap.js code and realized what was going on.
If you call the collapse function without initializing the collapse element as javascript, Bootstrap will automatically initialize it first. Take a look at part of the new Collapse . You can understand why an already open item is not a problem here.
// COLLAPSE PLUGIN DEFINITION // ========================== function Plugin(option) { return this.each(function () { var $this = $(this) var data = $this.data('bs.collapse') var options = $.extend({}, Collapse.DEFAULTS, $this.data(), typeof option == 'object' && option) if (!data && options.toggle && option == 'show') options.toggle = false if (!data) $this.data('bs.collapse', (data = new Collapse(this, options))) if (typeof option == 'string') data[option]() }) } var old = $.fn.collapse $.fn.collapse = Plugin
This is a collapse function:
var Collapse = function (element, options) { this.$element = $(element) this.options = $.extend({}, Collapse.DEFAULTS, options) this.$trigger = $(this.options.trigger).filter('[href="#' + element.id + '"], [data-target="#' + element.id + '"]') this.transitioning = null if (this.options.parent) { this.$parent = this.getParent() } else { this.addAriaAndCollapsedClass(this.$element, this.$trigger) } if (this.options.toggle) this.toggle() }
The last line is a period. If the toggle option is true, the toggle function is called. It opens a hidden folding element or closes the shown folding element:
Collapse.prototype.toggle = function () { this[this.$element.hasClass('in') ? 'hide' : 'show']() }
The toggle parameter defaults to true.
So, if you want to hide an element as shown below,
$('.panel-collapse').collapse('hide');
you need to initialize the element as follows:
$('#myCollapsible').collapse({ toggle: false });
You can find more information in Using crashes at boot .