* Johannes Löthberg <johannes@kyriasis.com> (Sun, 28 Jun 2015 21:22:05 +0200):
+function checkboxes() { + document.getElementById("pkglist-checked-count").innerHTML = document.querySelectorAll('input[type="checkbox"]:checked').length; +} + $(document).ready(function() { collapseDependsList("#pkgdepslist"); collapseDependsList("#pkgreqslist"); collapseDependsList("#pkgsrcslist"); + checkboxes(); // Set initial value + + var elements = document.getElementsByClassName('package-checkbox'); + + for (var i = 0, len = elements.length; i < len; i++) { + elements[i].onchange = checkboxes; + } });
What Carsten said; you know you can also declare a function with $(document).ready? That way, it isn't available outside of the function and you don't clutter the global namespace, for what it's worth.