Forked from Farmatique/gist:5c48d1d9b5744117a94901f6ed84f7b5
Last active
July 14, 2023 03:56
-
-
Save petertwise/ba6d2ba90dd70dcf855d9c20169b3b99 to your computer and use it in GitHub Desktop.
input[type="number"] plus/minus buttons
This file contains hidden or 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> |
This file contains hidden or 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
$('.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