If you have an image element, say an SVG. How do you retrieve the image code, in such a way that the output could look like the following
<svg ...></svg>
If you have an image element, say an SVG. How do you retrieve the image code, in such a way that the output could look like the following
<svg ...></svg>
Assuming you are using an img
tag that looks like this
<img src="whatever.svg">
you could find the value of src
and perform a fetch to that URL to get the underlying XML:
async function getSVGXML(selector) {
const url = $(selector).attr('src');
return await fetch(url).then(res => res.text());
}