Помогите найти общую сумму корзины при нажате плюс минус
как взять количество и получить окончательную сумму при клике изменить общую сумму
$(document).ready(function() {
function change($tr, val) {
var $input = $tr.find('.quantity');
var count = parseInt($input.val()) + val;
count = count < 1 ? 1 : count;
$input.val(count);
var $price = $tr.find('.count_price');
$price.text(count * $price.data('price'));
}
$('.minus').click(function() {
change($(this).closest('tr'), -1);
});
$('.plus').click(function() {
change($(this).closest('tr'), 1);
});
$('.quantity').on("input", function() {
var $price = $(this).closest('tr').find('.count_price');
$price.text(this.value * $price.data('price'));
});
});
<main>
<table class="shopping_list">
<tr>
<th>Image</th>
<th>Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
<th>Action</th>
</tr>
<?php
$total = 0;
include "basket/connect.php";
$sql = "SELECT * FROM `basket` ";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)){
?>
<tr>
<td><img src=img/<?php echo $row['image_url'];?>> </td>
<td><?php echo $row['name'];?> </td>
<td>$ <?php echo $row["price"];?></td>
<td>
<button class="minus" type="button" style="width:17%;">
<i class="fa fa-minus"></i></button>
<input class="quantity" type="text" value='<?php echo $row["quantity"]; ?>' style="width:17%;"/>
<button class="plus" type="button" style="width:17%;"><i class="fa fa-plus"></i></button>
</td>
<td><span class="count_price" data-price="<?php echo $row["price"]; ?>">$ <?php echo $row["price"]; ?> </span></td>
<td> <form method="POST" action='basket/delete.php ?id=<?php echo $row["id"] ?> '>
<input type="submit" name="delete" value="Remove">
</form></td>
<?php
$total = $total + ($row["quantity"] * $row["price"]);
?>
</tr>
<?php
}
}
?>
<tr>
<td colspan="4" align="right">Total</td>
<td class="n"> $ <?php echo number_format($total,2); ?></td>
<td></td>
</tr>
</table>
<div class="Pay for the order">
<a class="a1" href="login.php"><input type="submit" name="add_to_online-shopping"class="btn btn-success" value="Pay for the order" style="margin: 4% 0% 3% 44%;"/></a>
</div>
<script type="text/javascript" src="js/jquery-3.3.1.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<script type="text/javascript" src="js/script-1.js"></script>
<script type="text/javascript" src="js/script-3.js"></script>
</main>