-2

I'm probably doing something obviously wrong, but I just can't see it. I'm trying to use a for loop to define multiple click events and am experiencing an unexpected result. Some of this is working (the hide and show at the beginning of the function, but both sections wind up targeting the second item in the loop. Could somebody take a look at this and tell me what I'm doing wrong? Thank you so much for your help!

here is the link: http://grana.us/test/expand2.html

tisha
  • 1
  • 1
  • Post some code, so that we can help u. – Satpal Oct 26 '13 at 12:00
  • Questions concerning problems with code you've written must describe the specific problem — and **include valid code to reproduce it** — in the question itself. –  Oct 26 '13 at 12:06
  • @MikeW the problem is obvious in this case... – Flash Thunder Oct 26 '13 at 12:09
  • @FlashThunder That's not the point. If the OP removes the page at the link the question and the answers become meaningless. [so] is intended to become an archive of useful questions and answers that can be used in the future. –  Oct 26 '13 at 12:16

1 Answers1

1

You are assigning same event to all summaries for every id. This is wrong...

First... to hide all details and show all toglers simply use:

$('.details').hide();
$('.toggler').show();

And then define click function to all sumaries:

$('.summary').click(function(){
   if($('.toggler',this).html() == ' -'){
      $('.toggler',this).html(' +');
      $('.details',$(this).parent()).hide();
   }else{
      $('.toggler',this).html(' -');
      $('.details',$(this).parent()).show();
   }
});

Put everything in...

$(function(){
   ...
});

and should be ok.

Flash Thunder
  • 11,672
  • 8
  • 47
  • 91