Skip to content

Instantly share code, notes, and snippets.

@petertwise
Forked from Farmatique/gist:5c48d1d9b5744117a94901f6ed84f7b5
Last active July 14, 2023 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petertwise/ba6d2ba90dd70dcf855d9c20169b3b99 to your computer and use it in GitHub Desktop.
Save petertwise/ba6d2ba90dd70dcf855d9c20169b3b99 to your computer and use it in GitHub Desktop.
input[type="number"] plus/minus buttons
<div id="field1">
<button type="button" id="sub" class="sub">-</button>
<input type="text" id="1" value="0" class="field" />
<button type="button" id="add" class="add">+</button>
</div>
$('.add').click(function () {
$(this).prev().val(+$(this).prev().val() + 1);
});
$('.sub').click(function () {
if ($(this).next().val() > 0) $(this).next().val(+$(this).next().val() - 1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment