Selector and Iterating Through a Table Within a Div

Posted by GregH on Stack Overflow See other posts from Stack Overflow or by GregH
Published on 2009-12-12T04:31:32Z Indexed on 2010/03/26 2:53 UTC
Read the original article Hit count: 329

I have been working on this and cannot get this iterator to work. I have the following HTML and am trying to iterate through all rows (except the first row) and extract the values in cells (td) 2 and 3 :

<div id="statsId">
   <table width="220" cellspacing="0" cellpadding="0" border="0">
      <tbody>
         <tr>
            <td width="65"/>
            <td width="90"/>
            <td width="65"/>
         </tr>
         <tr style="font-weight: bold;">
            <td align="left">$1.00</td>
            <td>
               <a href="#">UserID1</a>
            </td>
            <td>Single</td>
         </tr>
         <tr>
            <td align="left">$6.99</td>
            <td>
               <a href="#">UserID2</a>
            </td>
            <td>Multiple</td>
         </tr>
         <tr>...
     .....(snip)

I tried the following iterator to iterate through all except the first row of the table that is a child of "div#statsID" and get the values of the 2nd and 3rd cells (in the example, the first extracted cells would have values of "UserID1" and "Single"), but it doesn't work.

$('div#statsId > table tr:not(:nth-child(1))').each(function(i, ele) {
		   var secondCol = $('td:nth-child(2)', ele).innerHTML
		   var thirdCol= $('td:nth-child(3)', ele).text()
    .....
  });

Any suggestions on how to specify and iterate through the rows (except the first) of a table that is a child of a div would be appreciated.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript