jQuery find image in div and save src as variable to use as css background image
<p>I have several divs on a page that have 1 randomly generated image in each div. I need to be able to find the image source value for each of those images and save them to a variable. I then need to assign those images as background css to other elements on the page. Example:</p>

<pre><code>&lt;div class="wrapper div1"&gt;&lt;img src="/image1.png" /&gt;&lt;/div&gt;
&lt;div class="wrapper div2"&gt;&lt;img src="/image2.png" /&gt;&lt;/div&gt;
&lt;div class="wrapper div3"&gt;&lt;img src="/image3.png" /&gt;&lt;/div&gt;

&lt;div class="background div1"&gt;&lt;/div&gt;
&lt;div class="background div2"&gt;&lt;/div&gt;
&lt;div class="background div3"&gt;&lt;/div&gt;
</code></pre>

<pre class="lang-js prettyprint-override"><code>$(function() {
    var div1Image = $('.wrapper.div1').find('img').attr('src');
    var div2Image = $('.wrapper.div2').find('img').attr('src');
    var div3Image = $('.wrapper.div3').find('img').attr('src');
    $('.background.div1').css('background-image', "url(' + div1Image + ') no-repeat");
    $('.background.div2').css('background-image', "url(' + div2Image + ') no-repeat");
    $('.background.div3').css('background-image', "url(' + div3Image + ') no-repeat");
});     
</code></pre>

<p>This code does nothing though. Am I going about this all wrong? Any thoughts as to what I am missing here? Thanks</p>