Created
August 28, 2014 16:07
-
-
Save ChrisMBarr/2c7722fc70cce32a40e2 to your computer and use it in GitHub Desktop.
A simple way to swap out .svg files linked by images with the actual <svg> source so you can control colors, etc. with CSS.
This file contains hidden or 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
$(function(){ | |
$("img[src$='.svg']").each(function(i,el) { | |
$.get(el.src, function(data) { | |
var svg = $(data).find('svg'); | |
if (svg) { | |
$(el).replaceWith(svg); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If we have this in our HTML:
Now, run the JS above and we can control the svg's fill color, among other things.