[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

jquery UI accordion

Hi Experts,

How can I set a jquery accordion to be closed by default when the page loads?

thanks,

HNM
0
HelpNearMe
Asked:
HelpNearMe
  • 4
  • 2
1 Solution
 
hieloCommented:
set the option:
collapsible:true

and then "click" the first element of the accordion. Save the attached code as test.html and try it:
<!DOCTYPE html> 
<html lang="en"> 
<head> 
	<base href="jqueryui.com/demos/accordion/collapsible.html" />
	<meta charset="utf-8"> 
	<title>jQuery UI Accordion - Collapse content</title> 
	<link rel="stylesheet" href="../../themes/base/jquery.ui.all.css"> 
	<script src="../../jquery-1.6.2.js"></script> 
	<script src="../../ui/jquery.ui.core.js"></script> 
	<script src="../../ui/jquery.ui.widget.js"></script> 
	<script src="../../ui/jquery.ui.accordion.js"></script> 
	<link rel="stylesheet" href="../demos.css"> 
	<script> 
	$(function() {
		$( "#accordion" ).accordion({
			collapsible: true
		});
		$('#accordion>h3:eq(0)').trigger('click');

	});
	</script> 
</head> 
<body> 
 
<div class="demo"> 
 
<div id="accordion"> 
	<h3><a href="#">Section 1</a></h3> 
	<div> 
		<p>Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.</p> 
	</div> 
	<h3><a href="#">Section 2</a></h3> 
	<div> 
		<p>Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In suscipit faucibus urna. </p> 
	</div> 
	<h3><a href="#">Section 3</a></h3> 
	<div> 
		<p>Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis. Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui. </p> 
		<ul> 
			<li>List item one</li> 
			<li>List item two</li> 
			<li>List item three</li> 
		</ul> 
	</div> 
	<h3><a href="#">Section 4</a></h3> 
	<div> 
		<p>Cras dictum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia mauris vel est. </p><p>Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. </p> 
	</div> 
</div> 
 
</div><!-- End demo --> 
 
 
 
 
</body> 
</html>

Open in new window

0
 
HelpNearMeAuthor Commented:
Hielo,

I am setting the header property for my accordion class to pick up H4 tags.  That works fine but when I add your collapsible property it's stops working.  What is the syntax for setting both properties:

i.e.

$(function() {
      
   $("#midPromoAccordionC").accordion({ header: "h4" collapsible: "true" });

});

Thanks,
HNM
0
 
hieloCommented:
>> header: "h4" collapsible: "true"
On the code you posted, you need a comma to the left of collapsible:
 header: "h4", collapsible: "true"
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
hieloCommented:
also, set collapsible to BOOLEAN true, not to a string that spells out true. In other words, no quotation marks around true
0
 
HelpNearMeAuthor Commented:
Had to thow in active: "none" to get it to work.

Thanks!

HNM

Another jquery comin' up.. keep an eye out for it
0
 
hieloCommented:
>>Had to thow in active: "none" to get it to work.
Thanks for the update.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now