counter plus minus Jquery

by tripcollor

HTML

<div class="number">
    <button class="minus">-</button>
    <input type="text" value="1" size="5"/>
    <button class="plus">+</button>
</div>

JavaScript

$('.minus').click(function () {
  var $input = $(this).parent().find('input');
  var count = parseInt($input.val()) - 1;
  count = count < 1 ? 1 : count;
  $input.val(count);
  $input.change();
  return false;
});
$('.plus').click(function () {
  var $input = $(this).parent().find('input');
  $input.val(parseInt($input.val()) + 1);
  $input.change();
  return false;
});