title: jQuery set CSS background opacity
body: <p>I have a <code>&lt;div&gt;</code> whose transparency of its <em>background-color</em> (and not its contents) I'd like to change. A remote API sends me this colour:</p>
  
  <pre><code>#abcdef
  </code></pre>
  
  <p>and I tell jQuery (1.9) to apply this colour via <code>.css</code>:</p>
  
  <pre><code>$('div').css('background-color', '#abcdef');
  </code></pre>
  
  <p>The resultant div has a <code>background-color</code> style of not <code>#abcdef</code>, but rather its RGB representation of the same colour.</p>
  
  <pre><code>background-color: rgb(171, 205, 239);
  </code></pre>
  
  <p>(Just an observation; not part of the problem)</p>
  
  <hr>
  
  <p>The project requirement has been changed such that I will now need to change the transparency of the background as well, to a set percentage (50%). My desired <code>background-color</code> attribute is thus</p>
  
  <pre><code>background-color: rgba(171, 205, 239, 0.5);
  </code></pre>
  
  <p>, however, I cannot find a way to set this background-color attribute using just jQuery, a hex colour code, and still apply an alpha value. <code>opacity</code> affects contents of the div as well as the background, so it is not an option.</p>
  
  <pre><code>$('div').css('background-color', '#abcdef')
          .css('opacity', 0.5);  // undesirable opacity changes to div's content
  </code></pre>
  
  <p>Given the string <code>#abcdef</code>, is it possible <em>only</em> by calculation (e.g. hex2dec) that I will be able to apply a background opacity to a div if I am given only a hex colour string?</p>