Hi,

I'm new to jQuery so please bear with me if this is a stupid question.  I
have gone through the tutorials on the site by the way, I just haven't found
a solution to it yet.

I have a page that is created on the fly using php.  On the page there are a
variable number of question-answer pairs.  Each question and answer is in
their own div and have their own unique ids.  Using the ready function I've
set each answer to be hidden - this was simple because each answer div has
the same class.  When a user clicks on the question, I want the answer to
appear underneath this.  I'm using the toggle() function for this.

It all works as expected.  However, in order to toggle the correct answer
div, I've hardcoded the div ids.  I need a way of identifying which question
was clicked on and then toggle the appropriate answer.  Is there anyway to
pass in an argument perhaps?

My generated html code is like:
<div class="questions">
 <div class="question" id="question_123">.......</div>
 <div class="answer" id="answer_123">........</div>
 <div class="question" id="question_739">.......</div>
 <div class="answer" id="answer_739">........</div>
</div>

My jQuery code is:

 $(document).ready(function () {
   $('div.answer').hide();
   $("#question_123").click(function() {   $("#answer_123").toggle();   });
   $("#question_739").click(function() {   $("#answer_739").toggle();   });
 });

Cheers,
Stella
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to