clarkk clarkk - 1 year ago 60
Javascript Question

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

How can you get all rows in a table without getting the rows in child tables?

var rows = $('tr', tbl);

This will return ALL
tags, including all rows in child tables.

Answer Source
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');


var rows = $(tbl).children('tbody').children('tr');

Here is a working example.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download