Link to home
Start Free TrialLog in
Avatar of tekgrl
tekgrl

asked on

Help with nested jQuery accordions

Hello.

I have a table (must be a table) where the row expands to reveal another row that also expands/collapses.

The problem is when I click on the sub-row to expand it the parent row collapses.

Here is my table:
<tr class="accordion">
	<td>
		<span></span><div class="head">Header 1</div>
	</td>
</tr>
<tr class="content">
	<td colspan="12">
		<table border="0" cellspacing="0" cellpadding="0" id="lit">
			<!-- panel -->
			<tr class="accordion">
				<td>
					<span></span><div class="head">Header 2</div>
				</td>
			</tr>
			<tr class="content">
				<td>Some content here</td>
			</tr>
		<!-- end panel -->
		</table>
	</td>
</tr>
<!-- end panel -->

Open in new window


...And here is the jQuery code:

$(document).ready(function() {
				
	//syntax highlighter
	hljs.tabReplace = '    ';
	hljs.initHighlightingOnLoad();

	//accordion
	$('tr.accordion').accordion({
		//defaultOpen: 'section1',
		speed: 'fast',
		animateOpen: function (elem, opts) { //replace the standard slideUp with custom function
			elem.next().slideFadeToggle(opts.speed);
		},
		animateClose: function (elem, opts) { //replace the standard slideDown with custom function
			elem.next().slideFadeToggle(opts.speed);
		}
	});

	

	//custom animation for open/close
	$.fn.slideFadeToggle = function(speed, easing, callback) {
		return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
	};

});

Open in new window


Please help!
Avatar of Gary
Gary
Flag of Ireland image

You would need to reclassify your nested accordion as a new accordion or try this plugin
http://www.adipalaz.com/experiments/jquery/nested_accordion.html
Avatar of lightspeedvt
lightspeedvt

Will be good to see the site.
Avatar of tekgrl

ASKER

There is no solution for my current code? I am showing you a VERY abridged version of what I have built. It will take me a long time to start over.

Hopefully someone out there can help me.

My code is attached.
my-accordion.zip
You have two solutions above. That is the only way - the jquery Accordion plugin is not designed for nested levels, that is why you have to declare a new accordion element with the parent Accordion.
Or use the other plugin
Avatar of tekgrl

ASKER

Hmmm, okay I'm game. How do I reclassify my nested accordion? I tried giving it a new name "accordion2" and duplicating the .js but that didn't do it.
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I've requested that this question be closed as follows:

Accepted answer: 500 points for hielo's comment #a39284828

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Well I gave a very simple answer - give the nested accordion a different class.
No messing about.