I use the jQuery script bellow to increment and decrement the quantity of items in my Magento cart, however the plus button is below the box and the minus button above.
Thinking this was a simple fix I switched the .append
and .prepend
parameters around but with no success.
This put the icons in the correct order but the functions simply stopped working. I'm assuming this is something to do with the order the functions are laid out below, however I'm not to savvy with jQuery!
jQuery(document).ready(function () {
jQuery("div.quantity")
.append('<input type="image" src="/checkout/plus.png" name="update_cart_action" value="+" id="add1" class="plus" />')
.prepend('<input type="image" src="/checkout/minus.png" name="update_cart_action" value="-" id="minus1" class="minus" />');
jQuery(".plus").click(function () {
var currentVal = parseInt(jQuery(this).prev(".qty").val());
if (!currentVal || currentVal == "" || currentVal == "NaN") currentVal = 1;
jQuery(this).prev(".qty").val(currentVal + 1);
});
jQuery(".minus").click(function () {
var currentVal = parseInt(jQuery(this).next(".qty").val());
if (currentVal == "NaN") currentVal = 1;
if (currentVal > 1) {
jQuery(this).next(".qty").val(currentVal - 1);
}
});
});