Looking to add the selected product along with its quantity and price to another div tag using the jQuery click function. Each time I click, only the first array value of the variable "product" is displayed.
How can I access the values of the current row for the table?
Utilizing Twig template:
<tr>
<td class="reference">{{product.reference}}</td>
<td class="product">{{product.productNr}} </td>
<td class="product">{{product.productDesp}} </td>
<td class="price">{{product.price}}</td>
<td class="input"><input type="text" /></td>
<td class="warenkorb"><button type='submit'>in den Warenkorb</button></td>
</tr>
<div id="cart">
<!-- Selected product by the user will appear here -->
???????
</div>
My JavaScript code:
$('.warenkorb').click(function(){
var reference = $('.reference').text();
alert(reference);
});
});
Data:
------------------------------------------------------
| reference | product | ProductNr | quantity | price |
______________________________________________________
|Jack store| Apple | 12435436 | 7 | 70€ |
______________________________________________________
|Bill store| Apple | 32534534 | 4 | 34€ |
______________________________________________________