cannot get the id of every row's last column in the table

I have a table which is dynamically built, what i want is that when i click, a function executes that give me the id of last column of every row, I used the following code where i alert every columns's id but it is not working . can any one help me ???? this is the loop which is used in the function

$('table[id="' + tableID + '"]').find('tr').each(function () {


what i get in the alert is the id of the first row's last column in every iteration of the loop


An alternative might be:

$('table#'+ tableID +' tr').each(function () {
    var lastCellOfCurrentRowId = $(this).find('td:last-child').attr("id");

The important thing is the $(this) inside the each iterator. It refers to current element on the iteration, for instance each row element (TR) on the table. From that element you can do whatever you need, for this case just find the last cell ID.

try this

$('table[id="' + tableID + '"] tr').each(function () {

You need to specify a context for the selector, so that you're looking for the last <td> inside the current row being looked at by the .each() function, so change it to:

alert($('td:last-child', this).attr("id"));

This will create a group of all the last TD's

$('#mytable tr td:last-child').each(function () {

As long as you only wanted to do this and not some more actions on each TR

Need Your Help

How to run a c program in ubuntu 12.04

c makefile ubuntu-12.04

Hello i am new to ubuntu. I want to run a c program in ubuntu.On the terminal i typed "make ex1.c" (my file name is ex1) and the after pressing enter button , terminal is telling me that

PySide QML project on android

android python qt qml pyside

I have made an application over pyside and qml for pc and I am interested to know how I can run this on android tablet.