?
Solved

jquery UI accordion

Posted on 2011-09-12
6
Medium Priority
?
310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

 
LVL 82

Accepted Solution

by:
hielo earned 2000 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

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

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

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

741 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