Selector to return closest <tr> only if table has more than 2 rows
Is there a selector available in jQuery to do something like:
$(this).closest('tr:count(tr>2)');
Context of this
is an <input>
element within a <td>
.
Disclaimer: I know this can be开发者_JAVA百科 done with .length
.size
.filter
.not
etc but I wonder if there is a nice way to do this just using CSS selectors.
Didn't test, but probably
$(this).closest('tr:not(:only-child)')
assuming a tr
will only have tr
sisters, which is not unreasonable.
Put your header in a <thead>
and your rows in a <tbody>
, as they should be. That way a simple selector such as the one given by @Amadan will work.tbody:has(tr)>tr
or
(Ok, I didn't quite think that selector through...)
精彩评论