开发者

Selector and Iterating Through a Table Within a Div

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.


$("#statsId > table tbody tr:not(:first)").each ( function() {
    var secondCol = $(this).find('td:nth-child(2)').html();
    var thirdCol= $(this).find('td:nth-child(3)').text();
});

Note

  1. You can use the id selector independently. No need to use the tag name.

  2. There is no innerHTML for a jQuery object. Use html() instead

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜