<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:svg="http://www.w3.org/2000/svg" >
  <head>
    <title>Scripting SVG with JS</title>
    <script>
      var counter=0;
      var colors=["red", "green", "blue"];
      
      function cycleColors()
      {
        document.getElementById("container").suspendRedraw(1000);
        var elem = document.getElementById("circle1");
        elem.setAttribute("style", "fill:"+colors[counter%3]);

        elem = document.getElementById("circle2");
        elem.setAttribute("style", "fill:"+colors[(counter+1)%3]);
        
        elem = document.getElementById("circle3");
        elem.setAttribute("style", "fill:"+colors[(counter+2)%3]);

        ++counter;
        document.getElementById("container").unsuspendRedraw(1000);

        setTimeout(cycleColors, 500);
      }
    </script>
    <style>
      circle:hover {fill-opacity:0.9; stroke-width:2mm;}
    </style>

  </head>

  <body onload="cycleColors();">
    <h1>Scripting SVG with JS</h1>
  <ul>
    <li>SVG object model is programatically accessible through XML DOM interfaces and SVG DOM interfaces.</li>
    <li>E.g. JavaScript can be used to manipulate object properties.</li>
  </ul>
  <pre style="background-color:#DDDDFF;">
    &lt;svg <strong>onload="cycleColors();"</strong> &gt;
    <strong>
    &lt;script&gt;
      var counter=0;
      var colors=["red", "green", "blue"];
      
      function cycleColors()
      {
        var elem = document.getElementById("circle1");
        elem.setAttribute("style", "fill:"+colors[counter%3]);

        elem = document.getElementById("circle2");
        elem.setAttribute("style", "fill:"+colors[(counter+1)%3]);
        
        elem = document.getElementById("circle3");
        elem.setAttribute("style", "fill:"+colors[(counter+2)%3]);

        ++counter;

        setTimeout(cycleColors, 500);
      }
    &lt;/script&gt;</strong>
    
    &lt;style&gt;
      circle:hover {fill-opacity:0.9; stroke-width:2mm;}
    &lt;/style&gt;
  
    &lt;g style="fill-opacity:0.7; stroke:black; stroke-width:0.1cm;"&gt;
    &lt;circle <strong>id="circle1"</strong> ... /&gt;
    &lt;circle <strong>id="circle2"</strong> ... /&gt;
    &lt;circle <strong>id="circle3"</strong> ... /&gt;
    &lt;/g&gt;
  &lt;/svg&gt; 
  </pre>

  
  <svg:svg id="container" width="12cm" height="12cm">
    <svg:g style="fill-opacity:0.7; stroke:black; stroke-width:0.1cm;">
      <svg:circle id="circle1" cx="6cm" cy="2cm" r="100" style="fill:red;" transform="translate(0,50)" />
      <svg:circle id="circle2" cx="6cm" cy="2cm" r="100" style="fill:blue;" transform="translate(70,150)" />
      <svg:circle id="circle3" cx="6cm" cy="2cm" r="100" style="fill:green;" transform="translate(-70,150)"/>
      <svg:rect x="0" y="0" width="12cm" height="12cm" style="fill:none;stroke:black; stroke-width:1;"/>
    </svg:g>
  </svg:svg> 
</body>
</html>