I have a table structured as follows:
<tr>
<td class="title">Title</td>
<td class="body">Body</td>
<td class="any">Any text</td>
</tr>
<tr>
<td class="title">Title</td>
<td class="body">Body</td>
<td class="any">Any text</td>
</tr>
<tr>
<td class="title">Title</td>
<td class="body">Body</td>
<td class="any">Any text</td>
</tr>
To toggle the visibility of the "body" td, I am currently using this script:
$('.title').append("<button class='moredrop'>↓</button>");
$(".moredrop").click(function(){
$(".body").toggle();
However, it toggles all td elements in the table. My goal is to only hide/show the specific td like demonstrated below:
$("tr").toggle(
function(){$(".body",this).css("display","block");},
function(){$(".body",this).css("display","none");});
Is there any way to achieve this functionality on button click?