javascript - jquery auto print the row number -



javascript - jquery auto print the row number -

i've table 10 row, possible print row number (from 1 9, first row no&title, sec row should 1) td class "sno" based on size of table? here html:

<table width="100%" border="1"> <tr> <td width="23%">no.</td> <td width="77%">title</td> </tr> <tr> <td class="sno">&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td class="sno">&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td class="sno">&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td class="sno">&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td class="sno">&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td class="sno">&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td class="sno">&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td class="sno">&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td class="sno">&nbsp;</td> <td>&nbsp;</td> </tr>

the result should

<table width="100%" border="1"> <tr> <td width="23%">no.</td> <td width="77%">title</td> </tr> <tr> <td class="sno">1</td> <td>&nbsp;</td> </tr> <tr> <td class="sno">2</td> <td>&nbsp;</td> </tr> <tr> <td class="sno">3</td> <td>&nbsp;</td> </tr> <tr> <td class="sno">4</td> <td>&nbsp;</td> </tr> <tr> <td class="sno">5</td> <td>&nbsp;</td> </tr> <tr> <td class="sno">6</td> <td>&nbsp;</td> </tr> <tr> <td class="sno">7</td> <td>&nbsp;</td> </tr> <tr> <td class="sno">8</td> <td>&nbsp;</td> </tr> <tr> <td class="sno">9</td> <td>&nbsp;</td> </tr>

the question not generate table, print right number target

here jsfiddle example: http://jsfiddle.net/3bben/

$(document).ready(function(){ //use special class name or id table //using find i'm getting tr elements in table //using not(':eq(0)') i'm ignoring first tr element //using each i'm iterating through selected elements $('table').find('tr').not(':eq(0)').each(function(i){ //using children('td:eq(0)') i'm getting first td element within tr $(this).children('td:eq(0)').addclass('sno').text(i+1); }); });

javascript jquery

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -