Royi Namir
Royi Namir

Reputation: 148524

How can I select all TR elements whose TDs don't contain a table?

How can I select:

I've tried:

var tbl = grd.find("tr:gt(0)").find("tr:not(:has(table)");

But this doesn't return any rows.

Upvotes: 2

Views: 142

Answers (3)

No Results Found
No Results Found

Reputation: 102745

You can use this selector:

var tbl = $("tr:not(:has(table)):not(:first)", grd);

Demo: http://jsfiddle.net/ZHTDq/

This selects rows in the tables that are <td> descendants as well, not sure if that's in your requirements or not.

Upvotes: 0

user1106925
user1106925

Reputation:

This assumes you're targeting the rows of the outermost table element.

$('#mytable > tbody > tr').slice(1)
                          .filter('tr:not(:has(table))');

http://jsfiddle.net/cvtqM/


Or if grd is the outer table...

grd.children()
   .children()
   .slice(1)
   .filter('tr:not(:has(table))');

Upvotes: 2

Esailija
Esailija

Reputation: 140220

grd.find("tr").slice(1).filter( function(){
    return !this.getElementsByTagName("table").length;
});

This is pretty reliant on whatever grd is.

Upvotes: 1

Related Questions