Last active
September 9, 2020 03:19
-
-
Save adrianjguerrero/2169a503d095acca2d574c8610f4e6a9 to your computer and use it in GitHub Desktop.
useful for when you need to get a very large svg and don't want to put it inline because it makes the page load very slow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getSvg = async (svgUrl, svgContainer) => { | |
let request = await fetch(svgUrl) | |
let svgText = await request.text() | |
const parser = new DOMParser(); | |
const svgHtml = parser.parseFromString(svgText, "text/html"); | |
svgContainer.appendChild(svgHtml.body.querySelector('svg')) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment