Count Checked Boxes with JQuery
Count the number of HTML check boxes, which are checked using this JQuery script.
$(document).ready(function() {
// ########## Count Boxes ########## //
function countBoxes() {
var a = $("input[type='checkbox']").length;
$('#boxes').text(' of ' + a + ' Checked');
}
countBoxes();
$(":checkbox").click(countBoxes);
// ########## Count Checked ########## //
function countChecked() {
var a = $("input:checked").length;
$("#checked").text(a);
}
countChecked();
$(":checkbox").click(countChecked);
});
Working demo on codepen.io
Written by James Barnett
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Jquery
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#