+ 3

How can i add a text in my svg shape?(pls i need ur help)

20th Jun 2019, 9:18 AM
Ebenezer Obiri
Ebenezer Obiri - avatar
2 Réponses
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); };
20th Jun 2019, 11:26 AM
Boris Batinkov
Boris Batinkov - avatar
+ 2
Thank u
20th Jun 2019, 12:27 PM
Ebenezer Obiri
Ebenezer Obiri - avatar