Jquery Selectors: Grabbing A Section Of Children That Are Of A Given Tag
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,
Solution 1:
You can use .slice()
for this, for example:
$("tr td").slice(2, 7)
//of if you have the <tr>
$(this).children("td").slice(2, 7)
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:
var tds = tr.getElementsByTagName("td");
for(var i = 2; i<7; i++) {
//do something
}
You can test both versions here.
Post a Comment for "Jquery Selectors: Grabbing A Section Of Children That Are Of A Given Tag"