Reputation: 99
I have a problem that I can't solve because I don't know enough about JS or jQuery.
I made a fiddle in order to illustrate a little bit what I've got http://jsfiddle.net/2TvAq/12/
So I have a foreach which will create a table that displays tournament for each tournament. (The fiddle is just an example of what I want to do)
And I have also a link "+more infos" which must display only the div with the description of the clicked tournament.
I have no idea how to do it, how to make a difference between one tournament or another.
Also, what I put in the div content is
<?php
<div style="display:none" class="ContentInfos">'. $tournoi->getDescription()
?>
but, the description is html code as text in the database, so I have html as plaintext in my div, if you also know a way to execute html tags instead it would be great, the only solution I got is this :
<?php
echo '<div style="display:none; text-align:left;" class="moreinfos"></div>
<div style="display:none" class="ContentInfos">'. $tournoi->getDescription() .'</div>'?>
And in the script :
$('.moreinfos').html($('.ContentInfos').text());
I know that it is ugly but I can't figure any other way to display it correctly.
Tell me if I'm not clear enough, I have difficulties to explain it.
Thank you for the time you take to help me!
Upvotes: 1
Views: 42
Reputation: 1084
Use this one:
$('.clickMe').click(function(event) {
event.preventDefault();
$(this).next('div').toggle();
});
I have updated you fiddle.
Upvotes: 1
Reputation: 36531
not sure if this is what you want .. but you can use siblings()
to toggle that particular div
only (in the fiddle)
example with your fiddle
$('.clickMe').click(function(event) {
event.preventDefault();
$(this).siblings('.content').toggle();
});
this will work if your a clickme
class and div content
is inside same container
Upvotes: 1