Last active
July 31, 2023 11:39
-
-
Save Farmatique/5c48d1d9b5744117a94901f6ed84f7b5 to your computer and use it in GitHub Desktop.
input[type="number"] plus/minus buttons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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