Reputation: 1050
I'm traversing a table with jquery, but I want to get the index of the tr at specific moments of the tranvers table:
$('table#tabla_materia tr').each(function()
{
if(typeof ($(this).find('input.cep').val()) !== 'undefined'){
// get the index here
rowIndex
}
// get the index of the new element
var nuevoRegistro = tbl_materia.insertRow(rowIndex+1);
nuevoRegistro.setAttribute('class', 'cep');
}
Can you help me please.
Upvotes: 1
Views: 267
Reputation: 193291
You can read either rowIndex
property of the HTMLTableRowElement, or use index
parameter passed to $.fn.each
callback.
$('table#tabla_materia tr').each(function (index) {
console.log(index, this.rowIndex);
// ...
});
Well, to be exact, index
in $.fn.each
callback is actually the index of the table row element in corresponding jQuery collection. However if you don't have nested tables this index will correspond to the actual rowIndex
property.
Upvotes: 1