Created
July 30, 2015 10:58
-
-
Save KacperOlszewski/71c8ac60495a142ea43b to your computer and use it in GitHub Desktop.
Input incremantation
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
$(".diet_counter p").on("click", function() { | |
var $button = $(this); | |
var $input = $(".diet_counter input"); | |
var oldValue = $(".diet_counter input").val(); | |
if ($button.text() == "+") { | |
var newVal = parseFloat(oldValue) + 1; | |
} | |
else { | |
if (oldValue > 1) { | |
var newVal = parseFloat(oldValue) - 1; | |
} | |
else { | |
newVal = 1; | |
} | |
} | |
$input.val(newVal); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment