foreach($products as $row){
<input type="hidden" class="prodId" name="id" value="<?php echo $row['id']; ?>">
<input type="hidden" class="prodUnique" name="unique" value="<?php echo $unique; ?>">
<button id="added" onClick="addToCart()" class="button btn-cart" title="Add to Cart" type="button"><span><i class="icon-basket"></i> Add to Cart</span></button>
}
<script>
function addToCart(){
var id = $(".prodId").val();
var unique = $(".prodUnique").val();
console.log(id);
}
</scritp>
Every time it is showing only first product ID. Means the id's are getting displayed properly in HTML, But When I console it in javascript, It shows same id. Suppose there are 4 products with ID 100, 101, 103, 105 displaying, then whenever I click on any product, the value every time getting consoled in javascript is 100.