It is possible to synchronously create a <svg>
element with Javascript that is a copy of a SVG file?
I have a small SVG in an external file called cursor.svg
located in a folder called svg
. So its relative path to my base HTML file is svg/cursor.svg
. The SVG is very simple:
<svg id="cursor">
<rect x="50" y="20" rx="20" ry="10" width="10" height="150" style="fill:red;stroke-width:0" opacity="0.75">
<animate attributeName="opacity" begin="indefinite" values="0.75;0" dur="1s" repeatCount="1" />
</rect>
</svg>
I would like to be able to have a createSvgNode()
function that simply returns a SVG node that is a copy of the one within cursor.svg
. (so that the function code would remains the same even if the SVG file changes)
But I want it to be synchronous. Is there a possible solution for this? Maybe by loading the cursor.svg
file in the HTML DOM?
Thanks for any suggestion.