Oops. I didn't close the if condition's parentheses. Sorry about that.
This line ...
if ($next.is(':visible') {
should be ...
if ($next.is(':visible')) {
--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
On May 16, 2008, at 2:25 PM, Karl Swedberg wrote:
HI Robin,
You can check for the visibility of the dd and then only show it if
it isn't visible to begin with.
Untested and unindented:
$(document).ready(function(){
$("dd:not(:first)").hide();
$("dt a").click(function(){
var $next = $(this).parent().next();
if ($next.is(':visible') {
$("dd:visible)").slideUp("slow");
} else {
$("dd:visible)").slideUp("slow");
$next.slideDown("slow");
}
return false;
});
});
--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
On May 16, 2008, at 1:51 PM, [EMAIL PROTECTED] wrote:
I'm brand new to jquery, and I need a little help with this simple
accordion menu code:
$(document).ready(function(){
$("dd:not(:first)").hide();
$("dt a").click(function(){
$("dd:visible)").slideUp("slow");
$(this).parent().next().slideDown("slow");
return false;
});
});
The html is like this:
<dt><a href="/">Section</a></dt>
<dd>
<ul>
<li><a href="url">Item</a></li>
And so on...
It works nicely, but I don't know how to make it so that when you
click on a section title that is ALREADY open, it will close instead.
At the moment, it will close and then slide open again.
I'm sure there's a simple condition that will fix it, but I'm
shooting
in the dark at the moment and can't seem to do it.
Any help much appreciated.