title: Get color of DIV in hex format JQuery
body: <p>This is my code:</p>
  
  <pre><code>function getTraits(trait) {
      $("#"+trait).on("click", function() {
          alert($(this).css('backgroundColor'));
          if (toHex($(this).css('background-color')) != highlightedColor) {
              $("#"+trait).css("background-color", highlightedColor);
              // If the element isn't highlighted, highlight it.
          } else {
              $(this).css("backgroundColor", defaultColor);
          }
      })
  }
  </code></pre>
  
  <p>I am trying to toggle a highlight on a div on the user's click. I would like to get the background color of the div because it would be inefficient to store a boolean toggle for each and every div. So I want a <code>toHex(rgb)</code> function. I saw a lot of those on SO, so I tried  using them and none of them worked. The <code>alert()</code> I put to show me the format JQuery was returning gave me <code>rgba(0,0,0,0)</code>. I attempted to modify a regex I found like this:</p>
  
  <p><code>var rgb = rgb.match(/^rgba((\d+),\s*(\d+),\s*(\d+))$/);</code></p>
  
  <p>That failed to work with a TypeError: <code>rgb is null</code>.</p>
  
  <p>Thanks for any help you can give me!</p>