Skip to content

Instantly share code, notes, and snippets.

@aseredenko
Created December 4, 2017 19:57
Show Gist options
  • Save aseredenko/3b3288f9ef8c1b8e44a9c18f2bced071 to your computer and use it in GitHub Desktop.
Save aseredenko/3b3288f9ef8c1b8e44a9c18f2bced071 to your computer and use it in GitHub Desktop.
(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