jquery selector to filter out th elements
I have:
var rows = $table.find('tbody > tr').get();
This selects all rows. However, not all tables have thead and tbody explicitly defined, so 开发者_如何学JAVAI need to filter out any rows that have .children('th')
EDIT: I'm assuming you wanted to filter out the rows that have <th>
elements. If you wanted to end up with only those rows, then just get rid of the :not()
part.
This will give you <tr>
elements in the table that do not have a descendant <th>
.
var rows = $table.find('tr:not(:has(th))').get();
- http://api.jquery.com/not-selector/
- http://api.jquery.com/has-selector/
Note that this will also give consideration to nested tables. If there will be nested tables with <th>
tags, try this:
var rows = $table.find('tr:not(:has( > th))').get();
...which should limit the consideration of the <th>
tags to immediate children.
Why not change that to:
var rows = $table.find('tr > th').get();
EDIT:
var rows = $table.find("tr:has(th)").get();
精彩评论