Created
December 4, 2017 19:57
-
-
Save aseredenko/3b3288f9ef8c1b8e44a9c18f2bced071 to your computer and use it in GitHub Desktop.
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
(function(){ | |
var $element = $('#number'); | |
function increment(){ | |
var currentValue = $element.html(); // Get string contains in our element | |
currentValue = parseInt(currentValue); // Make integer from string | |
$element.html(currentValue++); | |
} | |
function decrement(){ | |
var currentValue = $element.html(); // Get string contains in our element | |
currentValue = parseInt(currentValue); // Make integer from string | |
// Сheck if currentValue not greater than 1 (becuse it shouldn't be possible to order 0 or -1 product) | |
if(currentValue < 1){ | |
currentValue = 0; | |
} else{ | |
currentValue--; | |
} | |
// Or if you want be very cool developer you can do like this (but better to keep all thing as simple as possible) | |
// currentValue = currentValue < 1 ? 1 : currentValue--; | |
$element.html(currentValue); | |
} | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment