Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all rows in the "current" table, and not from child tables

Tags:

jquery

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.

like image 544
clarkk Avatar asked Aug 10 '11 14:08

clarkk


People also ask

How to get rows from table using jQuery?

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.

How to find all tr in table using jQuery?

esc_txt = function () { return this. replaceAll('\n', ''). replaceAll('\t',''); } jQuery.


2 Answers

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.

like image 70
FishBasketGordo Avatar answered Dec 04 '22 17:12

FishBasketGordo


var count = $('#tableID').rows;

It works, because the selector will return a HTMLTableElement object.

like image 37
Luty Avatar answered Dec 04 '22 19:12

Luty