I want to show the first element of this collapsible accordion. I did some research in internet but in vain
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-7s5uDGW3AHqw6xtJmNNtr+OBRJUlgkNJEo78P4b0yRw= sha512-nNo+yCHEyn0smMxSswnf/OnX6/KwJuZTlNZBjauKhTK0c+zT+q5JOCx0UFhXQ6rJR9jg6Es8gPuD2uZcYDLqSw==" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha256-KXn5puMvxCw+dAYznun+drMdG1IFl3agK0p/pqT9KAo= sha512-2e8qq0ETcfWRI4HJBzQiA3UoyFk6tbNyG+qSaIBZLyW9Xf3sWZHN/lxe9fTh1U45DpPf07yj94KsUHHWe4Yk1A==" crossorigin="anonymous"></script>
<div class="accordion" id="accordion2">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne" >
Aller au dossier personnel d'un agent
</a>
</div>
<div id="collapseOne" class="accordion-body collapse" style="height: 0px; ">
<div class="accordion-inner">
<form action="goToAgent.do" method="post">
<p align="center">
<input type="hidden" value="identite" name="retour">
<label for="nomPrenom" >
Entrer le nom complet de l'agent:
</label>
<input type="text" name="nomPrenom" class="typeahead" /> <br>
<input type="submit" value="appliquer" class="btn btn-info" />
</form>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
Ajout d'un nouveau fonctionnaire
</a>
</div>
<div id="collapseTwo" class="accordion-body collapse">
<div class="accordion-inner">
<!-- lorem -->
</div>
</div>
</div>
</div>
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.
How do you close one accordion when another opens? open accordian > at right side go to accordian seting > scrol down to Expand/Collapse Accordion Option On Page Load > choose Hide/close All Accordion..
The collapse JavaScript plugin is used to show and hide content. Buttons or anchors are used as triggers that are mapped to specific elements you toggle. Collapsing an element will animate the height from its current value to 0 .
This can be done by setting the 'active' property of jQuery Accordion as false.
You also can trigger a clic on the first collapse element
$("#accordion a:first").trigger("click");
Update for v4 :
The class .show
can be used on the .collapse
element to open it.
<div class="accordion" id="accordion-parent">
<a data-toggle="collapse" href="#collapseOne"></a>
<div id="collapseOne" class="collapse show" data-parent="#accordion-parent"></div>
<a data-toggle="collapse" href="#collapseTwo"></a>
<div id="collapseTwo" class="collapse" data-parent="#accordion-parent"></div>
</div>
Here's the same example working with v4 : Demo v4 (jsfiddle)
Bootstrap v2
If you add the .in
class to the .collapse
, it stays open :
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
Ajout d'un nouveau fonctionnaire
</a>
</div>
<div id="collapseTwo" class="accordion-body collapse in">
<div class="accordion-inner">
</div>
</div>
</div>
Demo (jsfiddle)
You do need to remove the style="height: 0px;"
from the .collapse
element if you want it to be displayed.
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