title: How to prevent addClass and removeClass repetition
body: <p>I'm adding active class to the buttons, and also i'm adding list/grid class to the cards-wrapper based on the button clicked. 
  Below is the working code. is there a way to write less code to achieve the same output?</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>$('.buttons button').click(function(e) {
        e.preventDefault();
        $('button').removeClass('active');
        $(this).addClass('active');
  
      if ($(this).hasClass('list')) {
          $('.cards-wrapper').removeClass('grid').addClass('list');
      }
      else if($(this).hasClass('grid')) {
          $('.cards-wrapper').removeClass('list').addClass('grid');
      }
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="buttons"&gt;
    &lt;button class="grid"&gt;Grid&lt;/button&gt;
    &lt;button class="list active"&gt;List&lt;/button&gt;
  &lt;/div&gt;
  
  &lt;div class="cards-wrapper list"&gt;
    &lt;div&gt;Sample Content&lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>