+ 3
How can i add a text in my svg shape?(pls i need ur help)
2 Respostas
0
Here is some JavaScript code:
var xmlns = "http://www.w3.org/2000/svg";
window.onload = function () {
var mySvg = document.createElementNS(xmlns, "svg");
mySvg.setAttribute("viewBox", "0 0 500 500");
mySvg.setAttribute("width", "300px");
mySvg.setAttribute("height", "300px");
mySvg.style.background = "#DDD";
var text = document.createElementNS(xmlns, "text");
text.innerHTML = "Hello World!";
text.setAttribute("x", 250);
text.setAttribute("y", 250);
text.setAttribute("text-anchor", "middle");
text.setAttribute("dominant-baseline", "central");
text.style.fontSize = "2em";
mySvg.appendChild(text);
document.body.appendChild(mySvg);
};
+ 2
Thank u