Update: Let's have another take at this.
Basically, you want to match all the <input>
elements that are descendants of #first
and that are not children of <td>
elements nested more than one level deep under #first
.
(I'm not sure about that last under #first
part, but implementing it allows us to support <td>
elements above #first
in the ancestor chain.)
Technically, the following selector alone should fulfill your requirements:
var inputs = $("#first td:not(#first td td) > input");
If this does not work in your browser (Sizzle should be up to the task I think, but complex selectors like :not()
are always tricky), you can delegate the processing to jQuery methods:
var inputs = $("#first td").not("#first td td").children("input");
Original answer follows:
You can use not() to exclude <input>
elements that have more than one <td>
ancestor:
var firstLevelCells = $("#first").find("input").not("td td input");