SVG not displaying
I have a function that returns an SVG element like so:
That code works fine with the VS code live server. But when I use it in a local dev server, the
<path>
and <polygon>
elements' width and height become 0.
this is my CSS code:
NOTE:
in the VS code live server, the SVG element is hardcoded into the HTML, it is not rendered by a JavaScript function, but the SVG element code is identical in both cases.
Any idea what could be doing wrong?
Thanks in advance.13 Replies
mmm it should create the correct nameSpace but you could try just creating it with to make sure.
Document: createElementNS() method - Web APIs | MDN
Creates an element with the specified namespace URI and qualified name.
oh you did I'm blind xD
well you are setting it... yea I'd
createElementNS('http://www.w3.org/2000/svg', 'svg')
or what notokay, i'll try
thing is, i did this many times before, i even have a function that toggles between to SVGs to show and hide a text in a password input like so :
and its working fine..
right but injecting html string with innerHTML != to creatingElement
that is going to take any valid html string and inject it
the other one you are creating the node
that is probably why you had to do the nameSpace when setting the attribute ya? cause it was trying to uncamel case viewBox?
NameSpaces are a w3c standard so like if you wanted to create xml you would have to tell JS the namespace too
Namespace
In computing, a namespace is a set of signs (names) that are used to identify and refer to objects of various kinds. A namespace ensures that all of a given set of objects have unique names so that they can be easily identified.
Namespaces are commonly structured as hierarchies to allow reuse of names in different contexts. As an analogy, consid...
learning RDF really opened my eyes to how all that worked but I've had to do it with both xml/svg when creating elements.
createElement assumes html nameSpacing but I thought it would do SVG proper but maybe not its elements inside.
i see..
what is RDF?
Resource Description Framework
The Resource Description Framework (RDF) is a World Wide Web Consortium (W3C) standard originally designed as a data model for metadata. It has come to be used as a general method for description and exchange of graph data. RDF provides a variety of syntax notations and data serialization formats, with Turtle (Terse RDF Triple Language) currentl...
a rabbit hole...
xD
xD
i'll read about, thanks a lot