namespace
SVG and HTML have different namespaces. When HTML is read and parsed by the browser and it finds an <svg>
tag, it automatically applies the correct namespace.
But if you just append an <svg>
tag into the DOM yourself, that SVG won’t have the correct namespace by default, and thus it won’t behave like an SVG element.
To create a new SVG element in JavaScript with the proper namespace, you need to do something like this:
That goes for the SVG element and any child SVG element you append.
Last updated