Yii Framework Forum: Yii with JQuery - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii with JQuery toggle slide the data from db Rate Topic: -----

#1 User is offline   tanimgt 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 51
  • Joined: 07-April 11
  • Location:Bangladesh

Posted 17 April 2011 - 11:39 PM

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>
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,336
  • Joined: 12-October 09
  • Location:Croatia

Posted 18 April 2011 - 02:40 AM

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();
});

Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   tanimgt 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 51
  • Joined: 07-April 11
  • Location:Bangladesh

Posted 18 April 2011 - 07:02 AM

View Postmdomba, on 18 April 2011 - 02:40 AM, said:

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 ....
0

#4 User is offline   Pep 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 06-August 11

Posted 14 May 2012 - 10:34 AM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users