I have a Bootstrap collapse panel in my webpage. I need to execute a function after the transition is complete and the panel has expanded fully. I have found this example for how to access the callback when the panel is collapsing and hidden.bs.collapse
is added.
How to trigger a JavaScript function after "Bootstrap: collapse plugin" transition is done.
But using similar code I can't seem to trigger when the .collapse.in
class is applied.
$('#collapseExample').on('.collapse.in', function(){
alert("hi");
});
I also found this code using promises to trigger a function after a class is toggled. It is supposed to wait until all animations are complete. jquery function on toggleClass complete? This does not seem to work for my problem either.
So I ask: How do I trigger a function when the collapse function is done?
This snippet attempts the jQuery promise technique. Ideally it would add the class .red
after the panel is done expanding but it triggers immediately.
http://www.bootply.com/Vx9oeyYy03#
$(document).on('click', '.btn', function(){
$('#collapseExample').collapse("toggle").promise().done(function () {
$('.well').addClass('red');
})
});