title: jquery dynamically change svg image xlink:href
body: <p>I'm trying to dynamically change the polygon's fill with an image not a fill color. To do so, I found a way to change the fill to an image, but I'm unable to dynamically change the xlink:href URL to a random url.
  Any thoughts? Thanks for your help!</p>
  
  <pre><code>&lt;svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" width="320px" height="480px" viewBox="0 0 320 480" enable-background="new 0 0 320 480" xml:space="preserve" xmlns:xml="http://www.w3.org/XML/1998/namespace"&gt;
  &lt;pattern patternUnits="userSpaceOnUse" id="pat1" x="10" y="10" 
   width="425" height="319"&gt;
      &lt;image id="background" width="100%" height="100%" 
       xlink:href="http://www.w3.org/1999/xlink" /&gt;
  &lt;/pattern&gt;
  &lt;g id="Layer_1"&gt;
      &lt;polygon class="background"  fill="url(#pat1)" points="265.188,329.922 160.198,358 55.208,329.922 55.208,120.868 265.188,120.868  "/&gt;
  
  &lt;/g&gt;
  &lt;g id="Layer_2"&gt;
      &lt;g id="brand_mark_1_"&gt;
          &lt;g&gt;
              &lt;rect x="265.188" y="120.868" fill="#FFFFFF" width="23.812" height="44.378"/&gt;
              &lt;g&gt;
                  &lt;path fill="#020304" d="M275.372,149.035c0,0.949,0.77,1.72,1.721,1.72c0.949,0,1.72-0.771,1.72-1.72      c0-0.023-0.003-0.044-0.004-0.066v-16.261c0.004-0.043,0.007-0.088,0.007-0.134c0-0.95-0.77-1.72-1.719-1.72      c-0.942,0-1.707,0.757-1.72,1.695h-0.005v16.461h0.001C275.374,149.017,275.372,149.025,275.372,149.035z"/&gt;
                  &lt;circle fill="#F5170D" cx="277.093" cy="153.541" r="1.72"/&gt;
              &lt;/g&gt;
          &lt;/g&gt;
      &lt;/g&gt;
  &lt;/g&gt;
  &lt;/svg&gt;
  
  
   $(document).ready(function() {
                  var randomColor = Math.floor(Math.random()*16777215).toString(16),
                      randomNumber = Math.floor((Math.random()*855)+48),
                      backg = $('#background');
                      $("body").css("background-color", randomColor);
                      backg.attr("http://www.w3.org/1999/xlink", "xlink:href","url(http://blob.apliiq.com/sitestorage/fabric/" + randomNumber + ".png)");
                      $('a#cta').attr("href", "/designyourown/?fabricID=" + randomNumber );               
              });
  </code></pre>