动态添加<a> to Embedded SVG

时间:2015-09-17 19:57:19

标签: javascript xml html5 svg

The script snippet below is for an svg embedded in an html document. The issue is that the svgMap.appendChild(cL); bit throws an error says appendChild is not a function which is ridiculous.

    var svgMap = document.getElementsByTagNameNS("http://www.w3.org/2000/svg", "svg");
    console.log(svgMap);
    var cId = document.getElementById(county[j][0]);
    var cL = document.createElementNS(null,"a");
    cL.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", "http://mtent.org/");
    svgMap.appendChild(cL);
    cL.appendChild(cId);
    console.log(cL);
    cId.setAttribute("class", "county");
    console.log(document.getElementById(county[j][0]));

1 个答案:

答案 0 :(得分:0)

didFinishLaunching...

注意[0] ... getElementsByTagName返回一个集合; - )