"Onclick add/sub Numbers using javascript"
Bootstrap 4.1.1 Snippet by iammohitverma

<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 ----------> <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/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="container"> <div class="row"> <form> <div class="form-check"> <input type="checkbox" class="form-check-input" id="exampleCheck1"> <label class="form-check-label" for="exampleCheck1">Check me out</label> </div> <div class="form-check"> <input type="checkbox" class="form-check-input" id="exampleCheck2"> <label class="form-check-label" for="exampleCheck2">Check me out</label> </div> <div class="form-check"> <input type="checkbox" class="form-check-input" id="exampleCheck3"> <label class="form-check-label" for="exampleCheck3">Check me out</label> </div> <div class="number"> <span id="num-text">0</span> </div> </form> </div> </div>
$(document).ready(function(){ $("input[type=checkbox]").click(function(){ $(this).closest(".form-check").toggleClass("active"); var numItems = $('.active').length; document.getElementById('num-text').innerHTML = numItems; }); });

Related: See More


Questions / Comments: