2010-12-23 27 views
7

Tengo 3 tablas con el mismo nombre de clase table-sort. Me gustaría tener acceso a los mesa por .each() y contar el tr dentro del tbody.

es que $("this tbody tr").length?

$('.table-sort').each(function(index) { 
    var rowCount = $("this tbody tr").length; //not work , Could you please correct this? 

    var rowCount1 = $(this).find('tbody > tr').length; //this is working fine 
    alert(rowCount + '-' + rowCount1); 
}) 

Respuesta

12

Aquí está el código

$('.table-sort').each(function(index) { 
    var rowCount = $("tbody tr", this).length; //will work now.. 

    var rowCount1 = $(this).find('tbody > tr').length; //this is working fine 
    alert(rowCount + '-' + rowCount1); 
}) 

Pero el segundo código que utilice, que trabaja, debería ser suficiente ..


También podría utilizar el inherent table properties of the table DOM object

$('.table-sort').each(function(index) { 
     var rowCount = this.rows.length; 
    }) 
+0

Gracias Gaby, es increíble, respuesta rápida. – Jahangir

+0

funciona increíble !! –

Cuestiones relacionadas