I have a rather basic implementation of a jQuery Accordion on a page (using 1.3.2, jQuery UI Core 1.72 and jQuery UI Accordion 1.7.2), and I wish to open the 2nd section when the page loads. i've tried numerous methods but nothing seems to work...
HEAD SCRIPT:
<script type="text/javascript"> $(function() {
$("#accordion").accordion({
event: "mouseover"
});
});
BODY ACCORDION:
<div id="accordion">
<h3><a href="#">Headline 001</a></h3>
<div>
<ul>
<li><a href="#1">Link 001</a></li>
<li><a href="#2">Link 002</a></li>
</ul>
</div>
<h3><a href="#">Headline 002</a></h3>
<div>
<ul>
<li><a href="#3">Link 003</a></li>
<li><a href="#4">Link 004</a></li>
</ul>
</div>
Any help would be greatly appreciated!
Do: $( "#accordion" ). accordion( "option", "active", 0 ); It will open the first element.
If you are using bootstrap accordion and want that one of the accordion should be opened for the first time so add class="in" .
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.
$("#accordion").accordion({ active: 2, event: "mouseover" });
Should do the trick!
UPDATE
if that doesn't work, try
$("#accordion").accordion({ event: "mouseover" }).activate(2);
(N.B. this is updated to be a bit faster, thanks for the comments. To be honest, it should work with the 'active: 2' parameter, don't know why it didn't.)
proper way to open a specific tab:
$("#accordion").accordion({
collapsible : true,
active : false,
heightStyle : "content",
navigation : true
});
Set the option:
//$("#accordion").accordion('option', 'active' , "INSERT YOUR TAB INDEX HERE");
$("#accordion").accordion('option', 'active' , 1);
or you could work with a hash like this:
if(location.hash){
var tabIndex = parseInt(window.location.hash.substring(1));
$("#accordion").accordion('option', 'active' , tabIndex);
}
Vote if you use ;)
Thanks
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