Putting CreateElementNS in a function (SVG Groups, shapes etc) <p>I am trying to turn this code right here:</p> <p><div class="snippet" data-lang="js" data-hide="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>var group = function(n){ n = document.createElementNS(svg, "g" ); }</code></pre> </div> </div> </p> <p>Am I doing it right? I have also tried with 'Return n = doc...' but that doesn't seem to work either.</p> <p>At the moment I just have allot of lines like this; </p> <p><div class="snippet" data-lang="js" data-hide="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>e.g1 = document.createElementNS(svg, "g" ); t2 = "translate("+e.x+" "+e.y+"), rotate("+e.z+" "+0+" "+0+")"; e.g1.setAttributeNS(null, "transform", t2); e.g1.setAttributeNS(null,"fill", "url(#gradient)"); e.g1.setAttributeNS(null,"stroke", "none"); e.g1.setAttributeNS(null,"stroke-width", e.a*0.03); document.getElementById("mySVG").appendChild(e.g1);</code></pre> </div> </div> </p> <p>Would prefer it to look more like this..</p> <p><div class="snippet" data-lang="js" data-hide="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code> group(e.g1); t2 = "translate("+e.x+" "+e.y+"), rotate("+e.z+" "+0+" "+0+")"; transform(e.g1, t2); fill(e.g1, url(#gradient)); stroke(e.g1, #000); strokewidth(e.g1, (e.a*0.03)); append(e.g1);</code></pre> </div> </div> </p> <p>Thanks, shorter code is what I need!</p>