Hi!
I try to add SVG path to a element via JS file. It is added to HTML page, but does not show.
But if I go to Inspect menu to see SVG and:
- Copy svg’s external HTML
- Delete svg
- Paste svg
Then it is show!
How to show it on normal work?
Hi!
I try to add SVG path to a element via JS file. It is added to HTML page, but does not show.
But if I go to Inspect menu to see SVG and:
How to show it on normal work?
I don’t know the details but SVG is a special kind of XML document so you need to specify a namespace, so something like this should work:
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
No changes. Shows only after copy-paste in inspector.
I forgot to mention, all SVG parts must be created using the document.createElementNS('http://www.w3.org/2000/svg', ...
So also the path
node:
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
That really should work .
Wow! Thanks, it works now.