loops - Based on user position, hide rows in table -5 and +5 after name (jquery) -


looking jquery scenario...

i displaying list of sports rankings on page table potentially contain couple of thousand players. display purposes, want show 5 rows before , 5 rows after logged in user.

for example, if had table info:

<table> <tr><td>person 1</td><td>999</td></tr> <tr><td>person 2</td><td>998</td></tr> <tr><td>person 3</td><td>997</td></tr> <tr><td>person 4</td><td>994</td></tr> <tr><td>person 5</td><td>992</td></tr> <tr><td>person 6</td><td>980</td></tr> <tr><td>person 7</td><td>970</td></tr> <tr><td class="me">person 8</td><td>960</td></tr> <tr><td>person 9</td><td>950</td></tr> <tr><td>person 10</td><td>940</td></tr> <tr><td>person 11</td><td>930</td></tr> <tr><td>person 12</td><td>920</td></tr> <tr><td>person 13</td><td>910</td></tr> <tr><td>person 14</td><td>900</td></tr> <tr><td>person 15</td><td>890</td></tr> </table> 

i'm logged in person 8. should see rows person 3 person 13.

i'm hoping find solution using loop jquery's prev() , next() functions.

any appreciated. in advance!

lots of indexes here, check code... (preview on jsfiddle)

// first index of row containing user var me_tr_index = $('tr')     .index($('tr')         .filter( function (){              return $('td.me', this).length;         })     );  // have our index, can use inside conditions $('tr').each( function (i) {     if(i < me_tr_index -2 || > me_tr_index +2)         $(this).css('color', 'red');     if(i === me_tr_index )         $(this).css('font-weight', 'bold'); }); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -