hi i want to loop through some tr’s like this .
<tr>
<td> <input type="radio" id="r11" value="a" name="r1_selectedobjects" /> </td>
<td><input type="radio" id="r12" value="b" name="r1_selectedobjects" /> <td>
</tr>
<tr>
<td><input type="radio" id="r21" value="a" name="r2_selectedobjects" /></td>
<input type="radio" id="r22" value="b" name="r2_selectedobjects" /></td>
</tr>
<td><input type="radio" id="r31" value="a" name="r3_selectedobjects" /></td>
<td><input type="radio" id="r32" value="b" name="r3_selectedobjects" /></td>
<tr>
<tr>
<td><input type="submit" id="matbutton" data-inline="true" value="Submit" onclick="return CheckMatrixRadio(this);" /></td>
</tr>
i can do this by $('tr').each(function(){});
i want to skip the 3 rd tr
this one
</tr>
<td><input type="radio" id="r31" value="a" name="r3_selectedobjects" /></td>
<td><input type="radio" id="r32" value="b" name="r3_selectedobjects" /></td>
<tr>
how to do this . think that i don’t know any calss or id names , only thing i know is index of my tr , in this case , 3
how to skip that tr in my each loop . please help………..
The
eachcallback receives a zero-based index telling you which matched item you’re looking at, so:If for any reason you don’t want to use
each(you mentioned it in your question, but just covering bases) but instead want to create a jQuery instance with all the rows except the third one, the most efficient way I know is:…which removes the third row from the matched set via
not. You could also achieve the same thing with a selector involving:notand:eq:…but then you’re requiring jQuery to process the selector rather than allowing it to pass the selector off to the browser’s
querySelectorAllimplementation (if it has one). *Examples of all three
(Side note: If there are unrelated
trs anywhere on the page, you may need to make your selector more specific to the group of rows you’re looking at.)* PiTheNumber points out in his answer that
$('tr:not(:nth-child(3))')should do it, too. And that’s useful because it has the advantage that both:notand:nth-childcan be processed by the browser natively. Note that:nth-childuses 1-based indexes, and is very different from:eq— it checks which child an element is of its container, not whether it’s the nth matched element. Should work for a table withtrelements provided they’re all in the sametbody, though.