We help IT Professionals succeed at work.

modify jquery to allow multiple control panels to remain open? (revisited)

Eric Bourland
on
Hi. I need further help with my collapsible accordion menu. =) I have set up an accordion menu, per this page: http://jqueryui.com/demos/accordion/. It works great.

However, I need to allow more than one control panel to stay open at the same time.

Jen0910 helped me with this question previously, and she provided a great solution:

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_27424221.html

However, when I use Jen's code I lose all of the formatting in the control panels.

You can see the existing accordion panels here:

http://www.ascassociation.org/collapse/collapsible.html

Is there a way to modify the code (please see below) to allow more than one control panel to stay open? And also keep the panel formatting?

Thank you again for your help.

Eric

<!DOCTYPE html>
			<link rel="stylesheet" href="base.css" type="text/css" media="all" />
			<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" type="text/css" media="all" />
			<link rel="stylesheet" href="http://static.jquery.com/ui/css/demo-docs-theme/ui.theme.css" type="text/css" media="all" />
			<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
			<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script>
           

<div id="demo-frame">
<!DOCTYPE html>


<!-- this is the original accordion script -->	
	<script>
	$(function() {
		$( "#accordion" ).accordion();
	});
	</script>



<!-- this is the script that Jen provided; it works very well, but it removes the formatting from the control panels -->
<script type="text/javascript">
         $(document).ready(function() {
                    $('div#accordion> div').hide();  
                    $('div#accordion> h3').click(function() {
                      $(this).next('div').slideToggle('slow')
                      .siblings('div:visible').slideDown('slow');
                    });
            });
</script>



<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 -->

Open in new window

Comment
Watch Question

Technically, what you seem to want is no longer an accordion, but that's OK.  I think you can fake it.

Try removing Jen's script, and changing the accordion setup to this:
	$(function() {
		$( "#accordion" ).accordion({disabled: true});

		$('h3').bind('click.Accordion', function() {
		var $h3 = $(this);
		$h3.toggleClass('ui-state-active')
			.find('span').toggleClass('ui-icon-triangle-1-s ui-icon-triangle-1-e');
			$h3.next().slideToggle(450);
		});
	});

Open in new window


Basically, use the jQueryUI to set up the accordion, but disable it.  Then add your own functionality.

Here's a link to jsFiddle: http://jsfiddle.net/kBFx6/1/

Author

Commented:
zappafan, thank you very much. I am working on this and will get back to you soon.

Eric

Author

Commented:
This is working really well. And, thank you for the link to the jsFiddle site. (I'm exploring it.) Thanks very much for your help, zappafan.

Eric

Explore More ContentExplore courses, solutions, and other research materials related to this topic.