Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <style>
    table, td {
      border: 1px solid #000000;
      border-collapse: collapse;
    }
  </style>
</head>
<body>
  <table>
    <tbody>
      <tr>
        <td>1</td>
        <td>2</td>
      </tr>
      <tr>
        <td>3, 4</td>
        <td>5, 6</td>
      </tr>
      <tr>
        <td>7, 8</td>
        <td>9</td>
      </tr>
    </tbody>
  </table>
  <script>
    var rows = document.querySelectorAll('tr'),
        totalRows = rows.length,
        rowCounter = 0,
        cols = null,
        totalColumns = 0,
        columnCounter = 0,
        row = [],
        csv = [];
    for (rowCounter = 0; rowCounter < totalRows; rowCounter++) {
      cols = rows[rowCounter].querySelectorAll('td');
      totalColumns = cols.length;
      row = [];
      for (columnCounter = 0; columnCounter < totalColumns; columnCounter++) {
        // quote each column in order to escape any commas
        row.push('"' + cols[columnCounter].innerText + '"');
      }
      
      csv.push(row.join(','));
    }
    console.log(csv.join('\n'));
  </script>
</body>
</html>
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
alarimerpro
0viewers