我有一个tspan -
<tspan>Some text</tspan>
我可以在Javascript中获取此元素
parentElement.lastChild -> this is tspan
如何在JavaScript中将x和y设置为2和4?所以它应该等同于
<tspan x="2" y="4">Some text</tspan>
答案 0 :(得分:1)
您应该使用setAttribute:
yourElement.setAttribute("x","2");
yourElement.setAttribute("y","4");