How can I make it so that the row highlights when the user clicks the up and down link? It just highlights every 2nd row but it also applies the highlighted row to the next row.
var rowCntr = 0;
$('table caption a:first').click(function (){
rowCntr++;
rowCntr = rowCntr + 1;
selector = 'tr:eq(' + rowCntr + ')';
$(selector).addClass("highlight");
return false;
});
var rowCntr2 = 0;
$('table caption a:last').click(function (){
rowCntr2++;
rowCntr2 = rowCntr2 - 1;
selector2 = 'tr:eq(' + rowCntr2 + ')';
$(selector2).addClass("highlight");
return false;
});
<h2>2: Zebra Striping Demo</h2>
<table width="200" border="1">
<caption><a href="#">UP</a> Zebra Striping Demo <a href="#">DN</a></caption>
<tr><td>January</td> <td>February</td><td>March</td></tr>
<tr><td>April</td><td>May</td><td>June</td></tr>
<tr><td>July</td><td>August</td><td>September</td></tr>
<tr><td>October</td><td>November</td><td>December</td></tr>
<tr><td>Monday</td><td>Tuesday</td><td>Wednesday</td></tr>
<tr><td>Thursday</td><td>Friday</td><td>Saturday</td></tr>
<tr><td>Spring</td><td>Summer</td><td>Fall</td></tr>
</table>
table caption {font-weight: bold}
table tr.over {background-color: red}
.odd {background-color:#EEE}
.even {background-color:#AAA}
.highlight {background-color:yellow}
Up and Dn: In the caption element are two anchor tags UP and DN. Clicking the UP link will cause the highlighted row class .highlight to move to the next row. Clicking the DN link will cause the highlighted row class .highlight to move to the previous row. Loop the effect around the table so that it doesn't stall when you reach the top or bottom of the table.

New Topic/Question
Reply



MultiQuote



|