DotDragnet
February 07, 2012, 02:27:49 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Help decide how we fund DDN and where we take the community from here. Post in the thread all about it: http://www.dotdragnet.com/forum/index.php/topic,4368.0.html
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Another jQuery that I can't get to grips  (Read 1124 times)
Charisma Bypass
Hero Member
*****
Posts: 511



View Profile Awards
« on: February 12, 2010, 03:59:47 PM »

OK, so html markup like this;

Code:
<dt>heading 1</dt>
  <dd>sub 1</dd>
  <dd>sub 2</dd>
  <dd>sub 3</dd>
<dt>heading 2</dt>
  <dd>sub 1</dd>
  <dd>sub 2</dd>
  <dd>sub 3</dd>
<dt>heading 3</dt>
  <dd>sub a</dd>
  <dd>sub b</dd>
  <dd>sub c</dd>

jquery;

Code:
$("dd:not(:first)").hide();

   $("dt a").click(function(){
       $("dd:visible").slideUp("fast");
       $(this).parent().next().slideDown("fast");
       return false;
   });

What I need to do is;
all dt's closed except first one, with all children showing.
when clicked on any other dt, the child dd's shows of that dt, and the already opened dt closes.

The jquery I have is very close but only shows the first dd of any dt, whereas I need to show all the dd's of the selected dt.  Phew.

Hope it makes sense.  It's basically an accordion menu.

Thanks in advance!
Logged
neal
Sr. Member
****
Posts: 300



nealio82
View Profile Awards
« Reply #1 on: February 12, 2010, 05:50:27 PM »

ok, basically your $(this).parent() selector only picks the first dd element. to pick them all you need to use the each function to iterate through them all.

i'm only starting to get to grips with jquery myself & i've not used the slide effects yet so i don't know how well this would work:

Code:
$("dd:not(:first)").hide();

   $("dt a").click(function(){
       $("dd:visible").slideUp("fast");
       $(this).siblings("dd").each(function() {
          $(this).slideDown("fast");
});
   });

(incidentally when i was writing 'myself' above i automatically wrote 'mysql' instead. guess what i've been writing all day!)
Logged

sig edited due to migrating from .net
samhs
Administrator
Hero Member
*****
Posts: 1669



View Profile WWW Awards
« Reply #2 on: February 12, 2010, 06:08:21 PM »

Code:
$(document).ready(function(){
 $("dt:not(:first) dd").hide();
 $("dt").click(function(){
   $(this).siblings("dt").find("dd").slideUp("fast");
   $(this).find("dd").slideDown("fast");
 });
});

untested but should work.
Logged

Loose adj a not held together; not fastened or firmly fixed in place
Lose verb to misplace something. To fail to keep or obtain something, especially because of a mistake, carelessness, etc.
---
Blog: www.ohwrite.co.uk
Twitter: www.twitter.com/samhs
Charisma Bypass
Hero Member
*****
Posts: 511



View Profile Awards
« Reply #3 on: February 13, 2010, 06:10:11 PM »

Thanks Guys, could get nothing to work, in the end gave up on dts and dds and went for uls and lis. 
Logged
civ
Full Member
***
Posts: 135



View Profile WWW Awards
« Reply #4 on: February 20, 2010, 01:18:03 AM »


(incidentally when i was writing 'myself' above i automatically wrote 'mysql' instead. guess what i've been writing all day!)

I do that all the time big grin
Logged

Oli
sarahA
DDN Contribs
Hero Member
*****
Posts: 2123



View Profile WWW Awards
« Reply #5 on: February 20, 2010, 01:10:12 PM »


(incidentally when i was writing 'myself' above i automatically wrote 'mysql' instead. guess what i've been writing all day!)

I do that all the time big grin

glad I'm not the only one wink
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!