I try edit button style when bootstrap collapse is show and when bootstrap collapsed is hidden. But when I first time click on the button, collapse is show but button style doesn't change. They change when i click button second time (then collapse is hidden)
My button:
<button type="button" class="btn-block" data-toggle="collapse" data-target="#demo1" id="demo1button">
Button
</button>
Collapse element
<div class="collapse" id="demo1">
...
</div>
Script
$("#demo1button").click(function(){
if(!$("#demo1").hasClass('show')){
$("#demo1button").addClass("collapsed");
}else{
$("#demo1button").removeClass("collapsed");
}
});
What's more, i try do this in other way and it still dosen't work
Script
$("#demo1button").click(function(){
if($("#demo1button").hasClass('collapsed')){
$("#demo1button").removeClass("collapsed");
}else{
$("#demo1button").addClass("collapsed");
}
});
Style.css
.collapsed{
background-color: #7a7a7a;
}