Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. var merch = document.getElementById('merch');
  2.  
  3. <td>
  4.  
  5. var merch = document.getElementById('merch');
  6.  
  7. // this will give you a HTMLCollection
  8. var rows = merch.rows;
  9.  
  10. // this will change the HTMLCollection to an Array
  11. var rows = [].slice.call(merch.rows);
  12.  
  13. // if you want the elements in the array be string.
  14. // map the array, get the innerHTML propery.
  15. var rows = [].slice.call(merch.rows).map(function(el) {
  16. return el.innerHTML;
  17. });
  18.  
  19. <table id="iterateOverThisTable">
  20. <tr>
  21. <td>One</td>
  22. <td>Two</td>
  23. <td>Three</td>
  24. </tr>
  25. <tr>
  26. <td>One</td>
  27. <td>Two</td>
  28. <td>Three</td>
  29. </tr>
  30. <tr>
  31. <td>One</td>
  32. <td>Two</td>
  33. <td>Three</td>
  34. </tr>
  35. </table>
  36.  
  37. $(function() {
  38. var rows = [];
  39.  
  40. $("#tableToIterateOver tr").each(function() {
  41. var = cells = [];
  42.  
  43. $(this).find('td').each(function() {
  44. cells.push($(this).text());
  45. });
  46.  
  47. rows.push(cells);
  48. });
  49. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement