I’m looping through a resultset which produces the following HTML:
<tr>
<td class="optionItems">
Test<br />
Test<br />
<a href="#" class="description" >
<img src="../../Images/Magnifying-Glass-icon.png"/> Description
</a>
</td>
<td colspan="2" class="optionItemsLast">
<input type="submit" value="Book" class="buttonGreen" />
</td>
</tr>
<tr>
<td colspan="3" class="optionItems">
<div class="slidingDiv">
Test><br />
</div>
</td>
</tr>
I have the following jQuery code to show/hide the div with the class name “slidingDiv”:
$(".slidingDiv").hide();
$(".description").show();
$('.description').click(function () {
$(".slidingDiv").slideToggle();
});
When I click on any of the links with the “description” class name, all the divs show. I just want to only show the div corresponding the “description” link I clicked on.
I’ve tried something like this:
$('.description').click(function () {
$(this).parent().children(".slidingDiv").slideToggle();
//$(".slidingDiv").slideToggle();
});
But with no success. Any help would be appreciated.
Try below code,
Assumption: That 2 tr are related and
.descriptionclosest tr’s next will be.slidingDiv‘s tr