title: jQuery: How to disable checkboxes only
body: <p>I am using the code below which I found on a website and it works perfectly.</p>
  <p>I have a 25 question-quiz made up of radio buttons and checkboxes.</p>
  <p>If on the same page I have both radio buttons as well as checkboxes, something goes wrong. The code below counts both of these, but I only want it to count the ticked off checkboxes.</p>
  <ul>
  <li>Currently once I hit the max answers, I cannot answer the remaining radio button questions; or vice versa, radio buttons before the checkboxes count towards the max number of answers.</li>
  <li>The code also disables both radio buttons and checkboxes, so I'd like to find a way to make it to disable the checkboxes only.</li>
  </ul>
  <p>I could split the code into even more divs, but that is going to become very complicated as my jQuery controls the flow of the quiz using divs:</p>
  <pre class="lang-js prettyprint-override"><code>$(document).ready(function () {
    $(&quot;input[type=checkbox]&quot;).click(function (e) {
      if ($(e.currentTarget).closest(&quot;div.question&quot;).length &gt; 0) {
        disableInputs($(e.currentTarget).closest(&quot;div.question&quot;)[0]);        
      }
    });
  });
  
  function disableInputs(questionElement) {
    console.log(questionElement);
    if ($(questionElement).data('max-answers') == undefined) {
      return true;
    } else {
      maxAnswers = parseInt($(questionElement).data('max-answers'), 10); 
      if ($(questionElement).find(&quot;:checked&quot;).length &gt;= maxAnswers) {
        $(questionElement).find(&quot;:not(:checked)&quot;).attr(&quot;disabled&quot;, true);
      } else {
        $(questionElement).find(&quot;input[type=checkbox]&quot;).attr(&quot;disabled&quot;, false);
      }
    }
  }
  </code></pre>
  <p>Here is a snippet of the main quiz:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;div class=&quot;Q8 question&quot; data-max-answers=&quot;3&quot;&gt;
    &lt;h2&gt;Access Control Questions&lt;/h2&gt;&lt;br&gt;
  
    &lt;strong&gt;Is it ok to share the door access code?&lt;/strong&gt;&lt;br&gt;
    &lt;input type=&quot;radio&quot; id=&quot;ac1&quot; name=&quot;access1&quot; value=&quot;0&quot;&gt;Yes&lt;br&gt;
    &lt;input type=&quot;radio&quot; id=&quot;ac2&quot; name=&quot;access1&quot; value=&quot;1&quot;&gt;No&lt;br&gt;&lt;br&gt;
    &lt;br&gt;&lt;strong&gt;&lt;label for=&quot;access1&quot;&gt;From the list below select those that are the aims of an Access Control System (Maximum of 3) &lt;/strong&gt;&lt;/span&gt;&lt;/label&gt;&lt;br&gt;
    &lt;input type=&quot;checkbox&quot; id=&quot;ac3&quot; name=&quot;access&quot;  value=&quot;1&quot; /&gt; To ensure only authorised users have access to our systems&lt;/p&gt;
    &lt;input type=&quot;checkbox&quot; id=&quot;ac4&quot; name=&quot;access&quot;  value=&quot;1&quot; /&gt; To protect physical access to our offices&lt;/p&gt;
    &lt;input type=&quot;checkbox&quot; id=&quot;ac4a&quot; name=&quot;access&quot; value=&quot;0&quot; /&gt; To give you access to other users passwords&lt;/p&gt;
    &lt;input type=&quot;checkbox&quot; id=&quot;ac5&quot; name=&quot;access&quot;  value=&quot;1&quot; /&gt; To ensure users have access to systems they require access too&lt;/p&gt;
  
    &lt;br&gt;&lt;strong&gt;A client is visiting and asks to use your computer, what should you do?&lt;/strong&gt;&lt;br&gt;
    &lt;input type=&quot;radio&quot; id=&quot;ac6&quot; name=&quot;access5&quot; value=&quot;0&quot;&gt;Let them use your computer because they are a client so can do what they wish&lt;br&gt;
    &lt;input type=&quot;radio&quot; id=&quot;ac7&quot; name=&quot;access5&quot; value=&quot;1&quot;&gt;Politely say you are not allowed to do that and refer them to the manager they have come to visit&lt;br&gt;
    &lt;input type=&quot;radio&quot; id=&quot;ac8&quot; name=&quot;access5&quot; value=&quot;0&quot;&gt;Pretend to be on a call and hope they go away&lt;br&gt;&lt;br&gt;
  &lt;/div&gt;
  
  &lt;div class=&quot;Q8a&quot;&gt;
    &lt;input id=&quot;Q8PrevBut&quot; type=&quot;button&quot; Value=&quot;Back&quot;&gt; 
    &lt;input id=&quot;Q8NextBut&quot; type=&quot;button&quot; Value=&quot;Next&quot;&gt; 
  &lt;/div&gt;
  </code></pre>