How can you get all rows in a table without getting the rows in child tables?
var rows = $('tr', tbl);
This will return ALL <tr>
tags, including all rows in child tables.
Approach 2: Use $('table tr:last') jQuery Selector to find the last element of the table. The 'table' in query looks for the table element then 'tr' is looking for all the rows in the table element and ':last' is looking for the last table row of the table.
esc_txt = function () { return this. replaceAll('\n', ''). replaceAll('\t',''); } jQuery.
var rows = $('#tblID > tbody > tr')
The child selector will get the table's <tbody>
element and consequently get the <tr>
elements that are direct children of the table's tbody.
If you already have a table object:
var rows = $(tbl).find('> tbody > tr');
Or:
var rows = $(tbl).children('tbody').children('tr');
Here is a working example.
var count = $('#tableID').rows;
It works, because the selector will return a HTMLTableElement object.
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