Created
November 24, 2016 11:12
-
-
Save nick-kravchenko/1192f5b4fb23106257deaabce8588a44 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($){ | |
$(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