I've looked around and can't seem to find a solution to directly replacing an element with a HTML string using vanilla JavaScript (not jQuery).
I'm storing a bunch of svg's in a directory that's publicly accessible, and I want to be able to include them in my files via the image tag <img src="path/to/svgs/example.svg">
. However, this comes with its drawbacks as they can't be coloured/styled when they're pulled in as an image (to my knowledgE).
I discovered this example jQuery Image to SVG but obviously this uses jQuery's replaceWith
function. I'm trying to replicate the functionality but struggling with the aforementioned function. All examples I've found end up creating a parent div
element, and appending the new HTML to that newly created element.
TL;DR: Can I directly replace an element (IMG to SVG) using vanilla JavaScript without creating parent nodes?