"plus minus counter input"
Bootstrap 4.1.1 Snippet by GR01

1
2
3
4
5
6
7
8
9
10
11
<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 ---------->
<div class="qty mt-5">
<span class="minus bg-dark">-</span>
<input type="number" class="count" name="qty" value="1">
<span class="plus bg-dark">+</span>
</div>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
.qty .count {
color: #000;
display: inline-block;
vertical-align: top;
font-size: 25px;
font-weight: 700;
line-height: 30px;
padding: 0 2px
;min-width: 35px;
text-align: center;
}
.qty .plus {
cursor: pointer;
display: inline-block;
vertical-align: top;
color: white;
width: 30px;
height: 30px;
font: 30px/1 Arial,sans-serif;
text-align: center;
border-radius: 50%;
}
.qty .minus {
cursor: pointer;
display: inline-block;
vertical-align: top;
color: white;
width: 30px;
height: 30px;
font: 30px/1 Arial,sans-serif;
text-align: center;
border-radius: 50%;
background-clip: padding-box;
}
div {
text-align: center;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
$(document).ready(function(){
$('.count').prop('disabled', true);
$(document).on('click','.plus',function(){
$('.count').val(parseInt($('.count').val()) + 1 );
});
$(document).on('click','.minus',function(){
$('.count').val(parseInt($('.count').val()) - 1 );
if ($('.count').val() == 0) {
$('.count').val(1);
}
});
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments:

Thanks.

rajucs (2) - 5 years ago - Reply 2


this doesn't work if the same page has multiple inputs, it edits the value of all inputs on the page.

Cappi1998 (1) - 3 years ago - Reply 1


this doesn't work if the same page has multiple inputs, it edits the value of all inputs on the page.

Cappi1998 (1) - 3 years ago - Reply 0