Created
October 18, 2020 05:05
-
-
Save motrdevua/70367d1613c39ee956acf3f6d78e0ad6 to your computer and use it in GitHub Desktop.
inline svg from img src
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
/** | |
* 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