title: How to check if any element has a class in jQuery?
body: <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>$(".Button").click(function (e) { 
      e.preventDefault();
      if (!$(this).hasClass("buttonActive")) {
          $(this).addClass("buttonActive");
      } else {
          $(this).removeClass("buttonActive");
      }
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.buttonActive {
      background: #100f10;
      color: white;   
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div id="numberSelect"&gt;
    &lt;button type="button" value="1" class="Button"&gt;1&lt;/button&gt;
    &lt;button type="button" value="2" class="Button"&gt;2&lt;/button&gt;
    &lt;button type="button" value="3" class="Button"&gt;3&lt;/button&gt;
    &lt;button type="button" value="4" class="Button"&gt;4&lt;/button&gt;
    &lt;input type="hidden" name="number" id="number"&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>What I wanna do is when I click on any button it checks if there is any other button has the class &quot;buttonActive&quot; and if any other button has this class it removes the class form the other button and add it to the button I clicked.
  So it should always be a single button which has the &quot;buttonActive&quot; class.</p>