Skip to content

Instantly share code, notes, and snippets.

@motrdevua
Created October 18, 2020 05:05
Show Gist options
  • Save motrdevua/70367d1613c39ee956acf3f6d78e0ad6 to your computer and use it in GitHub Desktop.
Save motrdevua/70367d1613c39ee956acf3f6d78e0ad6 to your computer and use it in GitHub Desktop.
inline svg from img src
/**
* Inline svg
*/
const allImg = document.querySelectorAll('img');
for (let i = 0; i < allImg.length; i++) {
const imgSrc = allImg[i].getAttribute('src');
if (imgSrc.split('.')[1] === 'svg') {
let myRequest = new Request(imgSrc);
fetch(myRequest)
.then((response) => {
return response.text();
})
.then((svg) => {
allImg[i].parentNode.innerHTML = svg;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment