I'm dynamically creating table rows. So each time I add a row, I need to get the ID of the last <tr>
so that I can create a new <tr>
with ID = "(the last row's ID) + 1"
. Is there any way to get the last row's ID using jQuery?
Approach 1: First, select the table by its ID. Use find() method to find the all table rows of the table. Use last() method to get the last row of table. The background color of the last element has been changed to see the effect.
To get the last record, the following is the query. mysql> select *from getLastRecord ORDER BY id DESC LIMIT 1; The following is the output. The above output shows that we have fetched the last record, with Id 4 and Name Carol.
Using the $('td:last') selector just selects the last td tag, i.e., c4.
jQuery Codealert($(". table"). find("tr:last"). find("td").
$('#yourtableid tr:last').attr('id');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With