dominornovus

Stopping decrementing at zero.

Apr 22nd, 2013
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.42 KB | None | 0 0
  1. /*http://stackoverflow.com/a/16139296/835950*/
  2.  
  3.     jQuery(".increment").on('click',function(){
  4.         jQuery(this).next(".amount input").val(parseInt(jQuery(this).next(".amount input").val())+1);
  5.     });
  6.  
  7.     jQuery(".decrement").on('click',function(){
  8.         var value = (parseInt(jQuery(this).prev(".amount input").val())-1);
  9.         jQuery(this).prev(".amount input").val((value-1) < 0 ? 0 :(value -1))
  10.     });
Advertisement
Add Comment
Please, Sign In to add comment