1
I am making a dynamic table in html and need to present the subtable only when clicking on the tr of the main table, follow the example.
$(function () {
$('#toggle3').click(function () {
$('.toggle3').toggle('slow');
return false;
});
});
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<table>
<thead>
<tr>
<th>Nome</th>
<th>Dependentes</th>
<th>Quantidade</th>
</tr>
</thead>
<tboby>
<tr>
<td>Fulano</td>
<td><a href="#" id="toggle3">convenio</a></td>
<td>3</td>
</tr>
<tr>
<td colspan="3">
<div class="toggle3" style="display:none;">
<table width="200" border="6">
<thead>
<tr>
<th>Nome</th>
<th>Tipo</th>
<th>Idade</th>
</tr>
</thead>
<tr>
<td>Maria</td>
<td>Esposa</td>
<td>47</td>
</tr>
<tr>
<td>Ana</td>
<td>Filha</td>
<td>12</td>
</tr>
<tr>
<td>Joaquim</td>
<td>Filho</td>
<td>06</td>
</tr>
</table>
</div>
</td>
</tr>
</tbody>
</table>
But in case I have multiple employees as I pass the id value dynamically?
Within the while
I put a variable $x++
that interacts with each new employee, and on the link I put the toogle name plus the interaction value
<a href="#" id="toggle<?php echo $x; ?>">link</a>
But I don’t know how to recover this value in javascript
Perfect @Thiagosantos was exactly what I was needing, solved the proposed problem. Thank you.
– WMomesso
@Wagnerfernandomomesso happy to help, we are here to strengthen the community, a hug :)
– Thiago Santos