Skip to content

Instantly share code, notes, and snippets.

@KacperOlszewski
Created July 30, 2015 10:58
Show Gist options
  • Save KacperOlszewski/71c8ac60495a142ea43b to your computer and use it in GitHub Desktop.
Save KacperOlszewski/71c8ac60495a142ea43b to your computer and use it in GitHub Desktop.
Input incremantation
$(".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