Lone SVG 01

Post tags: | svg |

Adding an svg circle with JavaScript

The script for adding the white circle.
        var svgele = null;
        svgele = document.createElementNS("http://www.w3.org/2000/svg", "circle");
        svgele.setAttribute("id", "circle1");
        svgele.cx.baseVal.value = 40;
        svgele.cy.baseVal.value = 40;
        svgele.r.baseVal.value = 40;
        document.getElementById('svgdefs').appendChild(svgele);
        
        svgele = document.createElementNS("http://www.w3.org/2000/svg", "use");
        svgele.setAttribute("id", "use3");
        svgele.setAttributeNS("http://www.w3.org/1999/xlink","href", "#circle1");
        svgele.style['stroke-width'] = "3px";
        svgele.style.fill = "White";
        svgele.style.stroke = "Black";
        document.getElementById('g1').appendChild(svgele);
        

Guides

Mardeg | craig: some known bugs with use: