size of createElement(“svg”) is 0,0

前端 未结 1 1786
夕颜
夕颜 2021-01-23 04:00

I want to create an SVG with JS and set the size, but when I use createElement(\"svg\"), the generated HTML is



        
相关标签:
1条回答
  • 2021-01-23 04:29

    createElement can only create HTML elements, you need createElementNS

    var svg=document.createElementNS("http://www.w3.org/2000/svg", "svg");
    document.body.appendChild(svg);
    svg.setAttribute("class","jscreated");
    svg.style.width="500px";
    svg.style.height="400px";
    <svg class="HTML_SVG" style="width:500px; height:400px;" class="HTML_SVG"></svg>

    0 讨论(0)
提交回复
热议问题