svg-inject

Replace an <img> element with an inline SVG.

svg-inject

Replace an <img> element with an inline SVG. This way you can still earn the benefits of not inlining every occurence of an SVG, but still style their contents using CSS selectors. This makes adding hover states and the like much more straightforward :)

Replace the <img> element with an SVG, calling callback(err, svg) when complete.

// Replaces all existing SVG images on the DOM with inline SVGs: 
var inject = require('svg-inject')
var svgs = document.querySelector('img[src$=".svg"]')
 
for (var i = 0; i < svgs.length; i++) {
  inject(svgs[i], function(errsvg) {
    if (err) throw err
    // do additional things with `svg` here if you like. 
  })
}

MIT. See LICENSE.md for details.