简体   繁体   中英

How to use svg text tag in javascript

I can use SVG Text tag in javascript. But its doesn't work. These is my code for Javascript.

O=evt.target;
Doc=O.ownerDocument;    
L = Doc.createElementNS(xmlns, "text");
L.setAttribute("x", 10);
L.setAttribute("y", 10);
L.node.textContent("abcdef");
L.setAttribute("fill", "red");
O.appendChild(L);

SVG Text Tag for Example:

<text x="10" y="10" fill="red">abcdef</text>

What type of error in my javascript code. Regards, Viji

This perfectly works

​<svg>
    <text x="10" y="10" fill="red">abcdef</text>
</svg>

H​​​​​​​​​​​​​ere is a working javavascript example . I don't have your complete code so it's hard to pinpoint your exact problem.

Edit: I think I found it. L.node.textContent("abcdef"); should be L.textContent = "abcdef"; new fiddle

More examples here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM