tags:

views:

621

answers:

3

Hi there... i have n-tables on a page. I need to go through every table on the page and within each table i need to add a class to the rows but NOT the first 5 rows.

my current js:

$('.selector').each(function(){
   var trCount = $("tbody > tr", this).size();
   alert(trCount);
});

this goes through and tells me how many tr's i have in each row. hoever i need to then go through each row and if the current row is more than the 5th row then add classes to it..

so hopefully i get the following.

<table class='selector'>
<tr><td>A</td></tr>
<tr><td>A</td></tr>
<tr><td>A</td></tr>
<tr><td>A</td></tr>
<tr><td>A</td></tr>
<tr class='hidden'><td>A</td></tr>
<tr class='hidden'><td>A</td></tr>
<tr class='hidden'><td>A</td></tr>
<tr class='hidden'><td>A</td></tr>
<tr class='hidden'><td>A</td></tr>
</table>
+2  A: 
$("table").each(function() {
  $("tr:gt(4)", this).addClass("hidden");
});

Note: the :gt(n) pseudo-class is zero-based so the first five rows are o to 4.

cletus
A: 

Does this go into the selector function??

Chris
A: 

One more question..i need this assignment to be done when a table sort is called..so that when i load the page the first 4 items are shown..perfect..however..when i run the tablesort it sorts by the other rows are still hidden..so i need to almost on sort remove all classes and reasign them to the new order..

Is this easy?

i am using the commonly used $("table").tablesorter();

can i add a function into this which calls the class assignement one..im not gd with jquery :S

thanks for your previous help however.. :)

Chris