Creating an SVG DOM element from a String

前端 未结 4 1943
天命终不由人
天命终不由人 2021-02-05 05:40

How would I go about creating an SVG DOM element from a String?

Example:

var svgStr = \'

        
4条回答
  •  耶瑟儿~
    2021-02-05 06:29

    Assuming you are using JavaScript, you can simply pass that string as the innerHTML of an existing element obtained via the DOM API:

    var svg2 = " ... ";
    var container = document.getElementById("container");
    container.innerHTML = svg2;
    

    See: JSFiddle

提交回复
热议问题