I have four HTML tables and have to compare data from one table with one that is selected by the user. I am passing the user-selected table ID into this function, but I don't know how to loop through the rows of this table:
function callme(code) {
var tableName = 'table'+code;
//alert(tableName);
//How to do loop for this table?? HELP!!
$('#tableName tr').each(function() { //how to do
if (!this.rowIndex) return; // skip first row
var customerId = $(this).find("td").eq(0).html();
alert(customerId);
// call compare function here.
});
}
It should be something very simple for a experienced jQuery programmer. Here is my jsfiddle: http://jsfiddle.net/w7akB/66/
You are using bad selector, this:
$('#tableName tr')
means get all tr
from table with id tableName
. This is what you want to do:
$('#' + tableName +' tr')
so you will select table with id stored inside tableName
variable.
The selector is just a string. You can concatenate the pieces together with your variable:
$('#' + tableName + ' tr').each(function() {
// ...
});
I updated your jsfiddle with this change.
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