Solved

jquery UI accordion

Posted on 2011-09-12
6
304 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

919 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

13 Experts available now in Live!

Get 1:1 Help Now