Solved

jquery UI accordion

Posted on 2011-09-12
6
301 Views
Last Modified: 2012-05-12
Hi Experts,

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

thanks,

HNM
0
Comment
Question by:HelpNearMe
  • 4
  • 2
6 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 36525556
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
 

Author Comment

by:HelpNearMe
ID: 36525966
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
 
LVL 82

Expert Comment

by:hielo
ID: 36526031
>> header: "h4" collapsible: "true"
On the code you posted, you need a comma to the left of collapsible:
 header: "h4", collapsible: "true"
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 36526095
also, set collapsible to BOOLEAN true, not to a string that spells out true. In other words, no quotation marks around true
0
 

Author Closing Comment

by:HelpNearMe
ID: 36526224
Had to thow in active: "none" to get it to work.

Thanks!

HNM

Another jquery comin' up.. keep an eye out for it
0
 
LVL 82

Expert Comment

by:hielo
ID: 36532004
>>Had to thow in active: "none" to get it to work.
Thanks for the update.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now