Bootstrap: Change Color of Panel Heading onClick

webforwork picture webforwork · Jul 10, 2015 · Viewed 16.7k times · Source

Hi I gave myself a crash course in bootstrap last night and I'm having a lot of fun with it. I found online a collapsible panel that works really well for what I am hoping to achieve in my navbar. However I want the background color of the panel heading to change when expanded. I am not familiar enough with the inner workings of bootstrap yet to noodle it out on my own (soon! I hope). Code in question is below:

            <div class="panel-group minmarg" id="accordion">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4 class="panel-title">
                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
                        OPI<b class="caret"></b>
                    </a>
                </h4>
            </div>
            <div id="collapseOne" class="panel-collapse collapse">
                <div class="panel-body minmarg">
                    <ul class="nav nav-pills nav-stacked pill-trngtheme minmarg">
                        <li role="presentation"><a href="#">OPI Main Site</a>
                        </li>
                        <li role="presentation" class="active"><a href="#">Training</a>
                        </li>
                        <li role="presentation"><a href="#">Procedures</a>
                        </li>
                        <li role="presentation"><a href="#">Corrective Action</a>
                        </li>
                        <li role="presentation"><a href="#">Human Performance Improvement</a>
                        </li>
                        <li role="presentation"><a href="#">LEAN Management</a>
                        </li>
                        <li role="presentation"><a href="#">Coduct of Operations</a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>

Answer

dieuvn3b picture dieuvn3b · Jul 10, 2015

You can reference to document

Here code for you:

$(".collapse").on('shown.bs.collapse',function(){
     // change background when expanded

});
$(".collapse").on('hidden.bs.collapse',function(){
     // change background when hide
});