Yii with JQuery

i posted it in related topics long time ago and found no proper solution. Can you please help me a little ?

I have a table with column: question and answer, i want, when i hover mouse on question the associative answer will display. I did this:




<div id="question">

<?php echo CHtml::encode($data->getAttributeLabel('ques')); ?>:

<?php echo CHtml::encode($data->ques); ?>

</div>


<div id="answer" style="display:none">

<?php echo CHtml::encode($data->getAttributeLabel('ans')); ?>:

<?php echo CHtml::encode($data->ans); ?>

</div>

<?php

Yii::app()->clientScript->registerScript('show', "

$('#question').hover(function(){

$('#answer').toggle();

});

");

?>

but it only toggles the first data, others are not showing. Please help me. Again Thanks alot. <tanim>

You need a way to get the DIV with the answer to a question just hovered…

if you use $(’#answer’).toggle() it will always toggle the first DIV with the ID answer…

For this to work you need a different structure… something like this :




<div class="question">

   your question

   <div>

  	your answer

   </div>

</div>



this way with jQuery you "know" which answer to toggle… something like




$('.question'),hover(function(){

   $('div',this).toggle();

});



Bro Thanks aaaa looooooooottttttttttttt… ;D this is worked …

You don’t need jQuery to do this. You can do it with CSS alone.




<style type="text/css">

.question .answer {display:none;}

.question:hover .answer {display:block;}

</style>


<div class="question">

   your question

   <div class="answer">

        your answer

   </div>

</div>



Your application should be more responsive if you use jQuery for what is essential plus users with javascript disabled will still get the same effect.