title: Change background color upon hover over with cursor
body: <p>I have a menu of buttons. Depending on the number of elements in a list (e.g., myList = ["A", "B", "C"]), I display the same number of buttons. For example, myList would make a menu of 3 buttons. </p>
  
  <p>Code for displaying buttons in a javascript plugin: </p>
  
  <pre><code>    html += '&lt;div id="buttonGallery"&gt;'
  
      // add as many buttons as there are letters
      _.map(myList, function(letters, ind) {   
        html += '&lt;div id="button_' + letters + '" class="buttons"&gt;';
        html += '&lt;p&gt;' + letters + '&lt;/p&gt;&lt;/div&gt;';
      }); 
  </code></pre>
  
  <p>I'm trying to change the background-color of each button when the user hovers over the buttons with their cursor. For example, "A" might become blue, "B" might become yellow, and "C" might become green upon hover. However, I don't know how to do this in css, because each button does not have a set id. </p>
  
  <p>I need my code to be as generalizable as possible, because in other cases, the list might be "D" and "E". In this other example, there would be 2 buttons that might turn orange and purple upon hover over. </p>
  
  <p>Does anyone have advice tackling this? Many thanks in advance! </p>
  
  <p>Below is a toy version of functional code: (but please note that this is NOT correct, because this example displays the buttons by <em>giving</em> them id's. Again, in the real version, I use the above code so that it is generalizable to all lists that I may run through it. In this example, you can see that all the buttons turn red on hover over.) </p>
  
  <pre><code>&lt;html lang="en" dir="ltr"&gt;
  
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"&gt;&lt;/script&gt;
    &lt;style media="screen"&gt;
      .buttons {
        width: 150px;
        height: 50px;
        border: solid 2px black;
        text-align: center;
        color: black;
        cursor: pointer;
        background-color: white;
        margin: 2px;
      }
  
      #buttonGallery {
        margin: 10px;
        padding: 10px;
        border: solid 2px black;
        width: 155px;
      }
  
      .buttons:hover {
        background-color: red !important;
        border: solid 3px black !important;
      }
  
      .selected {
        background-color: red !important;
        border: solid 3px black !important;
      }
    &lt;/style&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
    &lt;div id="buttonGallery"&gt;
      &lt;div class="buttons"&gt;
        &lt;p&gt;A&lt;/p&gt;
      &lt;/div&gt;
      &lt;div id="button_B" class="buttons"&gt;
        &lt;p&gt;B&lt;/p&gt;
      &lt;/div&gt;
      &lt;div id="button_C" class="buttons"&gt;
        &lt;p&gt;C&lt;/p&gt;
      &lt;/div&gt;
  
    &lt;/div&gt;
  
    &lt;script type="text/javascript"&gt;
      $('.buttons').click(function() {
      $(".buttons").not($(this)).removeClass("selected");
      $(this).toggleClass("selected");
    &lt;/script&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>(If any clarification is needed, I'm happy to receive feedback on how I can edit my post to be more clear. Thanks!) </p>