+ 1

How to add svg in JavaScript only ?

Hello everyone, What I'm trying to do is create a svg and add some drawing in it but all that in JavaScript. I can successfully add a svg element to my html using js, but when I try to add a circle to my newly made svg it doesn't show on my page. Here is a little code to illustrate my problem : https://code.sololearn.com/WFukF2EQVUzy/?ref=app Here you can see what I want in the green svg on top of screen, and what I get in the red svg at the bottom (the circle doesn't show for whatever reason). Does anyone have a solution, please ?

30th Oct 2019, 1:12 PM
Romain P.
Romain P. - avatar
3 Answers
+ 8
var mysvg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
30th Oct 2019, 2:50 PM
Kevin ★
+ 1
Thanks, this is the correct solution ! Didn't know I had to add that URL here too.
30th Oct 2019, 2:57 PM
Romain P.
Romain P. - avatar