"Bootstrap 4 Number Spinner"
Bootstrap 4.1.1 Snippet by mdwaris198

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <script src="https://kit.fontawesome.com/a076d05399.js"></script> <div class="container mt-5"> <div class="row"> <div class="col-md-4"></div> <div class="col-md-4"> <h4>Bootstrap 4 Number Spinner</h4> <hr> <div class="input-group mb-3 number-spinner"> <div class="input-group-prepend"> <button class="btn btn-danger" data-dir="dwn" type="button"><i class="fas fa-minus"></i></button> </div> <input type="text" class="form-control text-center" value="1"> <div class="input-group-append"> <button class="btn btn-danger" data-dir="up" type="button"><i class="fas fa-plus"></i></button> </div> </div> </div> <div class="col-md-4"></div> </div> </div>
$(document).on('click', '.number-spinner button', function () { var btn = $(this), oldValue = btn.closest('.number-spinner').find('input').val().trim(), newVal = 0; if (btn.attr('data-dir') == 'up') { newVal = parseInt(oldValue) + 1; } else { if (oldValue > 1) { newVal = parseInt(oldValue) - 1; } else { newVal = 1; } } btn.closest('.number-spinner').find('input').val(newVal); });

Related: See More


Questions / Comments: