title: Implementing buttons using css and jQuery
body: <p>I'm a complete beginner.</p>
  <p>I'm trying to implement two buttons that change colors (green to blue) with one click (and once the implementation is completed, integrating it to the actual website).</p>
  <p>The buttons need to do the following:</p>
  <ol>
  <li><p>Both the buttons are initially green. Once a button is clicked, it should change its color to blue.</p>
  </li>
  <li><p>And after that same button is clicked the second time, it should revert back to its original color which is green.</p>
  </li>
  <li><p>Only one button out of the two can be blue at a time. Which means as soon as the user clicks button-2 after clicking button-1, the button-1 should turn back to green, and button-2 to blue.</p>
  </li>
  </ol>
  <p>So far, I can implement the first and third ones, but not the middle one.</p>
  <p>Here are the necessary codes for it:</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>$(document).ready(function () {
  
      $('#btn1').click(function(){
          $('.btn').css('background-color', 'green');
          $(this).css('background-color', 'blue');
  
      })
  
      $('#btn2').click(function(){
          $('.btn').css('background-color', 'green');
          $(this).css('background-color', 'blue');
      })
  
    
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.btn {
      background-color: green;
  }</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;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
    
      &lt;meta charset="UTF-8"&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
      &lt;link rel="stylesheet" href="/styles.css"&gt;
  
      &lt;title&gt;Document&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;button id = "btn1" class = "btn"&gt;Button&lt;/button&gt;
      &lt;button id = "btn2" class = "btn"&gt;Button&lt;/button&gt;
      &lt;!--&lt;button id = "btn3" class = "btn" onclick="changeColor()"&gt;Button&lt;/button&gt;
      &lt;button id = "btn4" class = "btn" onclick="changeColor()"&gt;Button&lt;/button&gt; --&gt;
      &lt;script src="/jquery-3.6.1.min.js"&gt;&lt;/script&gt;
      &lt;script src="/index.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>