Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var merch = document.getElementById('merch');
- <td>
- var merch = document.getElementById('merch');
- // this will give you a HTMLCollection
- var rows = merch.rows;
- // this will change the HTMLCollection to an Array
- var rows = [].slice.call(merch.rows);
- // if you want the elements in the array be string.
- // map the array, get the innerHTML propery.
- var rows = [].slice.call(merch.rows).map(function(el) {
- return el.innerHTML;
- });
- <table id="iterateOverThisTable">
- <tr>
- <td>One</td>
- <td>Two</td>
- <td>Three</td>
- </tr>
- <tr>
- <td>One</td>
- <td>Two</td>
- <td>Three</td>
- </tr>
- <tr>
- <td>One</td>
- <td>Two</td>
- <td>Three</td>
- </tr>
- </table>
- $(function() {
- var rows = [];
- $("#tableToIterateOver tr").each(function() {
- var = cells = [];
- $(this).find('td').each(function() {
- cells.push($(this).text());
- });
- rows.push(cells);
- });
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement