Skip to content
Advertisement

How to get svg icon as a string from a .svg file

Is there a way to get svg icon as a string while you have the .svg file with JavaScript ?

To be more clear, I need a function which does:

JavaScript

Advertisement

Answer

You can use the fetch() function. The function svgFileToString() will not return anything, but you can replace console.log(text); with whatever.

For the example I’m using a data URL to replace the real path to a file.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement