title: How to use JS to dynamically change the color of a complex svg
body: <p>I want to use JavaScript to dynamically change the color of an image.  I was able to use JavaScript to load an svg path and change the color, but I also want to use a more complex image.  (E.g., the center oval should be black while I dynamically change the outer image color.)  </p>
  
  <p>Here's my simpler example: an oval with a hole missing; I can dynamically color this in JavaScript. 
  <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 color = 'red';
  var svgSource = "&lt;svg xmlns='http://www.w3.org/2000/svg' version='1.1' width='250' height='150'&gt;&lt;path stroke='black' stroke-width='2' fill='" + color + "' d='M 122.55664 14.691406 A 93.393089 51.964569 0 0 0 30.900391 67.289062 A 93.393089 51.964569 0 0 0 124.86133 118.61133 A 93.393089 51.964569 0 0 0 217.67969 66.648438 L 217.65039 65.365234 A 93.393089 51.964569 0 0 0 122.55664 14.691406 z M 91.923828 63.494141 A 47.749851 20.034533 0 0 1 140.54297 83.03125 L 140.55664 83.525391 A 47.749851 20.034533 0 0 1 93.101562 103.56055 A 47.749851 20.034533 0 0 1 45.060547 83.773438 A 47.749851 20.034533 0 0 1 91.923828 63.494141 z' /&gt;&lt;/svg&gt;";
  
  // display image
  document.getElementById("image").innerHTML = "&lt;img src=\"data:image/svg+xml;utf8," + svgSource + "\"&gt;";;</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="image"&gt;&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>Question: How can I do this with a more complicated path?</strong></p>
  
  <p>My more complicated object is made up of two paths, the color changing outer shape:</p>
  
  <pre><code>M 217.67871,66.647797 A 93.393089,51.964569 0 0 1 124.86224,118.61138 93.393089,51.964569 0 0 1 30.899652,67.289449 93.393089,51.964569 0 0 1 122.55587,14.692141 93.393089,51.964569 0 0 1 217.65023,65.364589
  </code></pre>
  
  <p>and a solid black inner oval defined by </p>
  
  <pre><code>M 140.55713,83.526031 A 47.749851,20.034533 0 0 1 93.102092,103.56018 47.749851,20.034533 0 0 1 45.061071,83.773416 47.749851,20.034533 0 0 1 91.922895,63.494936 47.749851,20.034533 0 0 1 140.54257,83.031301
  </code></pre>