I'm working on a ecommerce cart, which builds products by a PHP foreach() loop, adding each product in a <tr>.
This shop has 'bundled' products, meaning a couple of <tr>'s belong together as one big product.
The client asked me to edit the cart-view, add some stuff, move some around. So I used jQuery to add (i.e.) a legend after each head-item like so:
<tr>---- Item ----</tr>
<tr>Added row</tr>
<tr>Detail</tr>
<tr>Detail</tr>
<tr>---- Item ----</tr>
<tr>Added row</tr>
<tr>Detail</tr>
<tr>Detail</tr>
<tr>Detail</tr>
<tr>---- Item ----</tr>
<tr>Added row</tr>
<tr>Detail</tr>
<tr>Detail</tr>
<tr>Detail</tr>
<tr>Detail</tr>
Now, for various reasons I need to identify each group of products. I achieved this by adding a $i count in each head-item.
The problem is that the added row is made by jQuery, outside the foreach-loop, and so doesn't have the $i count like the rest of them, result like this:
<tr class="head_1">---- Item ----</tr>
<tr>Added row</tr>
<tr class="detail_1">Detail</tr>
<tr class="detail_1">Detail</tr>
<tr class="head_2">---- Item ----</tr>
<tr>Added row</tr>
<tr class="detail_2">Detail</tr>
<tr class="detail_2">Detail</tr>
<tr class="detail_2">Detail</tr>
<tr class="head_3">---- Item ----</tr>
<tr>Added row</tr>
<tr class="detail_3">Detail</tr>
<tr class="detail_3">Detail</tr>
<tr class="detail_3">Detail</tr>
<tr class="detail_3">Detail</tr>
What I need is to add the same count in a class to the added jQuery row. I'm clueless on how to, anyone?
Moar details
I add the row using jQuery('tr.head').after() like this:
jQuery( ".mainitem" ).after( "\
<tr class='addedrow'>\
<td class='product-remove'></td>\
<td class='product-thumbnail'></td>\
<td class='product-name'></td>\
<td class='product-price'></td>\
<td class='product-quantity'></td>\
<td class='product-subtotal'></td>\
</tr>"
);
and figured I could get the count of the added rows like this: var $rowcount = jQuery(".addedrow").length;