I´m using the DataTables table plug-in for jQuery. I have 4 columns, one of them contains buttons (Edit&Delete). I need to check the value of another column (in the same parent tr element) upon clicking one of the buttons using JavaScript/jQuery.
<tr role="row" class="odd">
<td class="sorting_1">0 <!-- I need this number --> </td>
<td>Exercise 1</td>
<td>nl</td>
<td class=" dt-center"> <!-- this element conatains the buttons --> </td>
</tr>
Could someone helpt me out? Thanks in advance. =)
When you click on the button, then you can ask for the closest tr
and then find the specific td
and ask for the text
inside it.
$(this).closest("tr").find(".sorting_1").text()
$('.getvalue').click(function() { console.log($(this).closest("tr").find(".sorting_1").text()) })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <tr role="row" class="odd"> <td class="sorting_1">0 </td> <td>Exercise 1</td> <td>nl</td> <td class=" dt-center"> <button class="getvalue">get value</button></td> </tr> <tr role="row" class="odd"> <td class="sorting_1">2</td> <td>Exercise 2</td> <td>n2</td> <td class=" dt-center"> <button class="getvalue">get value</button></td> </tr> </table>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.