showing results for - "jquery advace"
Louanne
09 Jan 2017
1$(document).ready(function(){
2   // cache this query since it's a search by CLASS
3   selectable = $(":checked.selectable");
4   // when the select/deselect all is clicked, do this function
5   $("#selectall").click(selectAll);
6   // whenever any individual checkbox is checked, change the text
7   // describing how many are checked
8   selectable.click(changeNumFilters);
9   // calculate how many are initially checked
10   changeNumFilters();
11});
12 
13var selectable;
14 
15function changeNumFilters()
16{
17   // this needs to be checked on every call
18   // since the length can change with every click
19   var size = $(":checked.selectable").length;
20   if (size > 0)
21      $("#selectedCount").html(size);
22   else
23      $("#selectedCount").html("0");
24 }
25  
26// handles the select/deselect of all checkboxes
27function selectAll()
28{
29   var checked = $("#selectall").attr("checked");
30   selectable.each(function(){
31      var subChecked = $(this).attr("checked");
32      if (subChecked != checked)
33      {
34         $(this).click();
35      }
36   });
37   changeNumFilters();
38   }
39