I have several comments on a site depending the post and I only want to show/hide the selected comments. I'm having this issue and trying to figure out. When I click on one option, the show/hide works fine but it's also hide or show on ANY others contents BELOW of it. I want the trigger to be able to show/hide ONLY one comment that have clicked.
Does anyone how to make slideToggle() works that way?
Here's the current code:
jQuery(document).ready(function()
{
// Slides container Up and Down on click
jQuery('div.toggle').click(function(event) {
// Get the ID by removing the '-'
$getID = event.target.id.split('-');
// Get the right content
$getContent = jQuery("div#content").parent().find("#"+$getID[1]);
// Check if content exist
if ($getContent.length > 0)
$getContent.slideToggle('slow');
});
});
**HERE is HTML code: Actually they're in a loop.
<?php while (have_posts()) : the_post(); ?>
<div class="toggle">
<ul id="nav">
<li><a href="javascript:;" id="option-view">View Comments /a></li>
...
</ul>
</div>
<div id="content">
<div id="view"><?php $withcomments = 1; comments_template(); ?></div>
</div>
<div id="add"> Add a COMMENT here!! </div>
<?php endwhile; ?>
***Finally, it's WORKING after spending almost a whole day to figure out HOW with trials and errors. Here's the code:
<div class="toggle">
<ul id="nav">
<li><a href="javascript:;" class="option-view" id="option-view">View Comments</a></li>
<li><a href="javascript:;" class="option-add" id="option-add">Add Comments</a></li>
</ul>
<div class="content">
<div id="view">.......VIEW a comment</div>
<div id="add">......Add a COMMENT here!!</div>
</div>
</div>
***JS code:
jQuery(document).ready(function()
{
jQuery('.toggle').bind("click", function(event) {
$getID = event.target.id.split('-');
//alert($getID)
jQuery(this).parent().find("#"+$getID[1]).slideToggle('slow');
return false;
});
});
Thanks to Half-Dead for helping to get right path...