Say I have an arbitrary number children (e.g. “td”s) of a given element (e.g. a “tr”), and I need to grab a given number of these (say, 4) at a given position (say, 3; td’s 3 – 67, in this case). What would the best query for doing this look like?
Note that I could be dealing with a potentially thousands of children, so I’d like to not be slicing up arrays in the thousands on a routine basis.
Edit: It doesn’t have to go through jQuery, if there’s a more efficient option that goes straight to the DOM…
You can use
.slice()for this, for example:The above would get the 3rd through 7th
<td>, since it’s a 0-based index. Or the jQuery-less version, say you have the<tr>DOM element:You can test both versions here.