title: Use array of ID's obtained from hrefs to target elements
body: <p>I'm having trouble why the below code isn't working as intended. I'm trying to obtain an array of ID's on the page from a content table, by saving the anchor tags <code>href</code> to the array. The array is constructed as I would have expected, but when I try to use it as the targeted element, nothing happens. I suspect that it's because the array is transformed into a string (which it would also seem from the console.log), but I still don't quite understand why it won't work. Do I have to transform the array into objects, and if so, how is that done? I haven't been able to find anything meeningful to me anywhere.</p>
  
  <p><strong>Edit:</strong> I have to do it this way (preferably at least) as the content table is meant to be created dynamically (not the same elements at all times), and the elements which the content table is pointing to should be styled accordingly.</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>var elements = [];
  $(".bb").each(function() {
    elements.push($(this).attr("href"));
  });
  console.log(elements);
  
  $(elements).each(function() {
    $(this).css("background", "red");
  });
  
  // This works for a single elment, however
  var el = $(".cc").attr("href");
  $(el).css("background", "green");</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code> body {
    padding-bottom: 100px;
   }
  div {
    height: 50px;
    margin-bottom: 10px;
    background: #d3fcff;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div id="aa"&gt;&lt;/div&gt;
  &lt;div id="xx"&gt;&lt;/div&gt;
  
  &lt;a class="bb" href="#aa"&gt;target #aa&lt;/a&gt;
  &lt;a class="bb" href="#xx"&gt;target #xx&lt;/a&gt;
  
  &lt;p&gt;Not using an array and targeting a single element works however&lt;/p&gt;
  &lt;div id="zz"&gt;&lt;/div&gt;
  &lt;a class="cc" href="#zz"&gt;target #zz&lt;/a&gt;</code></pre>
  </div>
  </div>
  </p>