Skip to content

Instantly share code, notes, and snippets.

@nick-kravchenko
Created November 24, 2016 11:12
Show Gist options
  • Save nick-kravchenko/1192f5b4fb23106257deaabce8588a44 to your computer and use it in GitHub Desktop.
Save nick-kravchenko/1192f5b4fb23106257deaabce8588a44 to your computer and use it in GitHub Desktop.
;(function($){
$(document).ready(function(){
$('<button type="button" class="dec">-</button>').prependTo( inputWrapper );
$('<button type="button" class="inc">+</button>').appendTo( inputWrapper );
$( inputWrapper ).on('click', 'button', function(){
if ( !$(this).parent().find('>input[type="number"]').val() ) {
var val = 0;
} else {
var val = parseInt($(this).parent().find('>input[type="number"]').val());
}
if ( $(this).hasClass('inc') ) {
$(this).parent().find('>input[type="number"]').val( val + 1 );
} else if( $(this).hasClass('dec') ) {
if ( val > 0 ) {
$(this).parent().find('>input[type="number"]').val( val - 1 );
}
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment