Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the last row of a table using jQuery?

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?

like image 629
Rosh Avatar asked May 24 '12 05:05

Rosh


People also ask

How can I get the last row value in a table 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.

How do I find the last row of a table?

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.

How can get last column of table in jQuery?

Using the $('td:last') selector just selects the last td tag, i.e., c4.

How do I get the second last row in a table using jQuery?

jQuery Codealert($(". table"). find("tr:last"). find("td").


1 Answers

$('#yourtableid tr:last').attr('id'); 
like image 129
coolguy Avatar answered Sep 22 '22 21:09

coolguy