In a Bootstrap accordion, instead of requiring a click on the a
text, I want to make it collapse when clicking anywhere in the panel-heading
div.
I am using Bootstrap 3. So instead of accordion, it's just a collapsible panel. Any idea how to do the entire panel clickable?
Just add data-toggle="collapse" and a data-target to the element to automatically assign control of one or more collapsible elements. The data-target attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse to the collapsible element.
To create an accordion that is collapsed by default, we need to set the 'active' property of the jQuery Accordion as false. Syntax: $("#demoAccordion"). accordion({ collapsible: true, active: false});
open accordian > at right side go to accordian seting > scrol down to Expand/Collapse Accordion Option On Page Load > choose Hide/close All Accordion.. thanks.
The . collapse class indicates a collapsible element (a <div> in our example); this is the content that will be shown or hidden with a click of a button. To control (show/hide) the collapsible content, add the data-toggle="collapse" attribute to an <a> or a <button> element.
All you need to do is to to use...
data-toggle="collapse"
data-target="#ElementToExpandOnClick"
...on the element you want to click to trigger the collapse/expand effect.
The element with data-toggle="collapse"
will be the element to trigger the effect. The data-target
attribute indicates the element that will expand when the effect is triggered.
Optionally you can set the data-parent
if you want to create an accordion effect instead of independent collapsible, e.g.:
data-parent="#accordion"
I would also add the following CSS to the elements with data-toggle="collapse"
if they aren't <a>
tags, e.g.:
.panel-heading { cursor: pointer; }
Here's a jsfiddle with the modified html from the Bootstrap 3 documentation.
Another way is make your <a>
full fill all the space of the panel-heading
. Use this style to do so:
.panel-title a { display: block; padding: 10px 15px; margin: -10px -15px; }
Check this demo (http://jsfiddle.net/KbQyx/).
Then when you clicking on the heading, you are actually clicking on the <a>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With