Skip to content

Instantly share code, notes, and snippets.

@webinmd
Last active June 20, 2018 07:20
Show Gist options
  • Save webinmd/ccd34ce9cb6fc00a3b6128a37f9cf048 to your computer and use it in GitHub Desktop.
Save webinmd/ccd34ce9cb6fc00a3b6128a37f9cf048 to your computer and use it in GitHub Desktop.
<div class="quantity">
<span class="bminus"></span>
<input type="number" name="count" value="1" min="1" required >
<span class="bplus"></span>
</div>
<script>
/* quantity count plus/minus
------------------------------------------------------*/
$('.bminus').on('click',function () {
var $input = $(this).parent().find('input');
var val = +$input[0].defaultValue;
var count = parseInt($input.val()) - 1;
count = count < 1 ? 1 : count;
$input.val(count);
$input.change();
return false;
});
$('.bplus').on('click',function () {
var $input = $(this).parent().find('input');
var val = +$input[0].defaultValue;
$input.val(parseInt($input.val()) + 1);
$input.change();
return false;
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment