Skip to content

Instantly share code, notes, and snippets.

@Farmatique
Last active July 31, 2023 11:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Farmatique/5c48d1d9b5744117a94901f6ed84f7b5 to your computer and use it in GitHub Desktop.
Save Farmatique/5c48d1d9b5744117a94901f6ed84f7b5 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