Loop to READ HTML Table

by Pankaj Sapkal

HTML

<table>
    <tbody>
        <tr>
            <td>63</td>
            <td>Computer</td>
            <td>3434</td>
            <td>
               <button type="button" class="use-address" />
            </td>
        </tr>
        <tr>
            <td>64</td>
            <td>Stationary</td>
            <td>111</td>
            <td>
               <button type="button" class="use-address" />
            </td>
        </tr>
        <tr>
            <td>64</td>
            <td>Accesiorries</td>
            <td>11</td>
            <td>
                <button type="button" class="use-address" />
            </td>
        </tr>
    </tbody>
</table>

JavaScript

var table = $("table tbody");
    var values = [];
    table.find('tr').each(function(i) {
      var $tds = $(this).find('td'),
        productId = $tds.eq(0).text(),
        product = $tds.eq(1).text(),
        Quantity = $tds.eq(2).text();
      // do something with productId, product, Quantity
      // alert('Row ' + (i + 1) + ':\nId: ' + productId
      // + '\nProduct: ' + product
      //  + '\nQuantity: ' + Quantity);
      values.push('\nId: ' + productId + '\nProduct: ' + product + '\nQuantity: ' + Quantity);
    });

    var myString = values.join(';');

    alert(myString);