title: Wrapping an anchor tag around dynamically generated divs
body: <p>I have a div that generates multiple elements inside it:</p>
  
  <pre><code> &lt;div class="lists"&gt;
                      &lt;?php for($i=0;$i&lt;6;$i++) { ?&gt;
                          &lt;div class="list history[[$i]]" id="history[[$i]]"&gt;  
                              &lt;div class="info"&gt;
                                  &lt;div class="picture monophoto"&gt;
                                      &lt;div class="text"&gt;BO&lt;/div&gt;
                                      &lt;div class="img" style="background-image: url();"&gt;&lt;/div&gt;
                                  &lt;/div&gt;
                                  &lt;div class="right"&gt;
                                      &lt;div class="lineone"&gt;John Smith&lt;/div&gt;
                                      &lt;div class="linetwo"&gt;Daily Essentials&lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="boxes"&gt;
                                  &lt;div class="left"&gt;
                                      &lt;div class="box box1"&gt;&lt;/div&gt;
                                  &lt;/div&gt;
                                  &lt;div class="right"&gt;
                                      &lt;div class="box box2"&gt;&lt;/div&gt;
                                      &lt;div class="box box3"&gt;&lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;a class="cbutton whiteonblack"&gt;VIEW LIST&lt;!--SEE &lt;span class="owner"&gt;JOHN'S&lt;/span&gt;--&gt;&lt;/a&gt;
                          &lt;/div&gt;
                      &lt;?php } ?&gt;
                  &lt;/div&gt;
  </code></pre>
  
  <p>I am trying to wrap the following div with an anchor tag so it links:</p>
  
  <pre><code>&lt;div class="boxes"&gt; &lt;/div&gt;
  </code></pre>
  
  <p>Using jQuery I am trying to wrap this using jQuery that is part of a loop:</p>
  
  <pre><code>                        for(var i = 0; i &lt; listLength; i++){
                              for(var y = 0; y &lt; result.history[i].length; y++){
                                  var history = document.getElementById('history' + i);
                                  history.querySelector('.boxes').wrap('&lt;a href="http://google.com"&gt;&lt;/a&gt;');
                              }
                          }
  </code></pre>
  
  <p>This is not resulting in an anchor tag showing up at all on the DOM. What am I doing wrong and how do I fix it?</p>
  
  <p>Edit: I clarified which div</p>
  
  <p>Edit 2: To clarify, each of the links are actually going to be dynamically generated. I am just using google.com as an example. So effecting all of a specific class wont work.</p>