SVG使用纯JavaScript进行移动

时间:2017-03-10 23:32:40

标签: javascript svg

我有一个tspan -

<tspan>Some text</tspan>

我可以在Javascript中获取此元素

parentElement.lastChild -> this is tspan

如何在JavaScript中将x和y设置为2和4?所以它应该等同于

 <tspan x="2" y="4">Some text</tspan>

1 个答案:

答案 0 :(得分:1)

您应该使用setAttribute

yourElement.setAttribute("x","2");
yourElement.setAttribute("y","4");