Skip to content

Instantly share code, notes, and snippets.

@jessehintze
Created August 7, 2015 17:57
Show Gist options
  • Save jessehintze/b9cbbdfc823fe29a75b6 to your computer and use it in GitHub Desktop.
Save jessehintze/b9cbbdfc823fe29a75b6 to your computer and use it in GitHub Desktop.
Click to add or subtract to qty box
//product page qty
$('.sp-plus').on('click', function(){
var newVal = (parseInt($('.sp-input').val(),10) +1);
var oldVal = parseInt($('.sp-input').val(), 10);
if (isNaN(oldVal) === true){
$('.sp-input').val(1);
} else {
$('.sp-input').val(newVal);
}
});
$('.sp-minus').on('click', function(){
var newVal = (parseInt($('.sp-input').val(),10) -1);
var oldVal = parseInt($('.sp-input').val(), 10);
if(oldVal <= 1) {
return false;
} else if (isNaN(oldVal) === true){
$('.sp-input').val(1);
} else {
$('.sp-input').val(newVal);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment