title: CheckAll/UncheckAll checkbox with jQuery
body: <p>I have made a check-box checkall/uncheckall.</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;div&gt; Using Check all function &lt;/div&gt;
  &lt;div id="selectCheckBox"&gt;
  &lt;input type="checkbox" class="all" onchange="checkAll('selectCheckBox','all','check','true');" /&gt;Select All
  &lt;input type="checkbox" class="check" onchange="checkAll('selectCheckBox','all','check','false');" /&gt;Check Box 1
  &lt;input type="checkbox" class="check" onchange="checkAll('selectCheckBox','all','check','false');" /&gt;Check Box 2
  &lt;input type="checkbox" class="check" onchange="checkAll('selectCheckBox','all','check','false');" /&gt;Check Box 3
  &lt;input type="checkbox" class="check" onchange="checkAll('selectCheckBox','all','check','false');" /&gt;Check Box 4
  &lt;/div&gt;
  </code></pre>
  
  <p>main.js</p>
  
  <pre><code>function checkAll(parentId,allClass,checkboxClass,allChecked){
      checkboxAll = $('#'+parentId+' .'+allClass);
      otherCheckBox = $('#'+parentId+' .'+checkboxClass);
      checkedCheckBox = otherCheckBox.filter($('input[type=checkbox]:checked'));
      if(allChecked=='false'){
          if(otherCheckBox.size()==checkedCheckBox.size()){
              checkboxAll.attr('checked',true);
          }else{
              checkboxAll.attr('checked',false);
          }
      }else{
          if(checkboxAll.attr('checked')){
              otherCheckBox.attr('checked',true);
          }else{
              otherCheckBox.attr('checked',false);
          }
      }
  }
  </code></pre>
  
  <p>It works fine. But get bulky when I have whole lot of checkboxes. I want to do same work by using jQuery rather than putting onchange on each checkbox. I tried different sort of things but couldnot work. I tried following one:</p>
  
  <pre><code>$('.check input[type="checkbox"]').change(function(e){
      checkAll('selectCheckBox','all','check','true');
  });
  </code></pre>
  
  <p>to do same work as onchange event but didnot work. Where do I went wrong.</p>