Hi i wrote a jquery script. I'm rookie on jquery. i want to increase cart count +1. But this script didn't add +1 it concats 1. What should i do ?
<script type="text/javascript">
$('#shopping-cart-button').click(function(){
var cart_count = $('#cart_count').text();
cart_count = cart_count + 1;
$('#cart_count').text(cart_count);
});
</script>
.text() returns string, so you have to use parseInt(value, radix) to convert the string to number.
$('#shopping-cart-button').click(function(){
var basket_count = $('#basket_count').text();
basket_count = parseInt(basket_count, 10) + 1;
$('#basket_count').text(basket_count);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With