Quantcast
Channel: User Chamilyan - Stack Overflow
Viewing all articles
Browse latest Browse all 43

Group Table Rows into an array

$
0
0

I need to group a variable amount of table rows into an array. Each group has 5 cells as shown in the HTML:

<tr> <td width='23%' class='table-item-1'><strong>EVP</strong></td> <td width='15%' class='table-item-1'>Diane</td> <td width='17%' class='table-item-1'>xxx-xxx-xxxx</td> <td width='17%' class='table-item-1'>xxx-xxx-6xxx</td> <td width='25%' class='table-item-1'>&nbsp;<a href='mailto:'></a></td> </tr> <tr> <td width='23%' class='table-item-1'><strong>EVP</strong></td> <td width='15%' class='table-item-1'>Leslee</td> <td width='17%' class='table-item-1'>xxx-xxx-xxxx</td> <td width='17%' class='table-item-1'>xxx-xxx-6xxx</td> <td width='25%' class='table-item-1'>&nbsp;<a href='mailto:'></a></td> </tr> <tr> <td width='23%' class='table-item-1'><strong>Production Mgr</strong></td> <td width='15%' class='table-item-1'><s>Lenny  </s>&nbsp; tbh</td> <td width='17%' class='table-item-1'>xxx-xxx-xxxx</td> <td width='17%' class='table-item-1'>xxx-xxx-6xxx</td> <td width='25%' class='table-item-1'>&nbsp;<a href='mailto:'></a></td> </tr> <tr> <td width='23%' class='table-item-1'><strong>Production</strong></td> <td width='15%' class='table-item-1'>Jessica</td> <td width='17%' class='table-item-1'>xxx-xxx-xxxx</td> <td width='17%' class='table-item-1'>xxx-xxx-2xxx</td> <td width='25%' class='table-item-1'>&nbsp;<a href='mailto:'></a></td> </tr>

Here is what I have so far:

var items_size = $('[width|="23%"]').size(); //gives me the amount of groupsvar items1 = {   'name': $('.table-item-1 ~ td').html(),'email': $('.table-item-1 ~ td > a').html(),'phone': $('.table-item-1 ~ td').next().html(),'fax': $('.table-item-1 ~ td').next().next().html(),'title': $('.table-item-1 ~ td').prev().children().html()        }; // creates an array containing the items from the first group.

I need to create the same array for each group in the HTML.


Viewing all articles
Browse latest Browse all 43

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>