-
-
Save jpsantos7/33be4bea05334aacb72b65d2c6004acd 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