title: jQuery toggle class on label onclick of radio
body: <p>I'm trying to toggle 'active' class on 2 labels when you click on radio/label. So on page load the first radio is checked and label for that radio has class 'active' then if you clicked on the other radio/label it would toggle the active class. I've almost got it working i'm just doing something slightly wrong.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$('.label_item input[type="radio"]').click(function() {
    if (!$(this).is(':checked')) {
      $(this).parent('.label_item').addClass('active');
    } else {
      $(this).parent('.label_item').removeClass('active');
    }
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;label class="label_item active" for="a1"&gt;
  &lt;input type="radio" name="radio" id="a1" checked="checked" /&gt;label one&lt;/label&gt;
  
  &lt;label class="label_item" for="a2"&gt;
  &lt;input type="radio" name="radio" id="a2" /&gt;label two&lt;/label&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>JSFiddle: <a href="https://jsfiddle.net/5vnhgduh/" rel="nofollow noreferrer">https://jsfiddle.net/5vnhgduh/</a></p>