Say I have the following table
<table>
<tr><td> #TD1 </td><td> #TD2 </td></tr>
<tr><td> #TD3 </td><td> #TD4 </td></tr>
<tr><td> #TD5 </td><td> #TD6 </td></tr>
<tr><td> #TD7 </td><td> #TD8 </td></tr>
<tr><td> #TD9 </td><td> #TD10 </td></tr>
<tr><td> #TD11 </td><td> #TD12 </td></tr>
<tr><td> #TD13 </td><td> #TD14 </td></tr>
</table>
With jquery how do I select
I'm interested in an adaptable solution as my table might vary in columns and rows and I might need to select 4 rows going down rather than just three.
So far I've got
$("table tr:gt(1) td:nth-child(1)").css('color','red')
but it doesnt stop at #TD11
See also http://jsfiddle.net/2ygJk/
Try:
$("table tr:gt(1):lt(3)").css('color','red')
http://jsfiddle.net/2ygJk/4/
jQuery Filter is your friend
var indexes = [5,7,9]; // the indexes you would like to filter out
var filterdCelles = $('td').filter(function(i){
return indexes.indexOf(i) > -1;
})
And then you can just do:
filterdCelles.css('color','red'); // changes the font to this color
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With