Last active
January 8, 2017 12:38
-
-
Save SashaKolbasov/9bcb906da5d80376665a1f62dcd528c5 to your computer and use it in GitHub Desktop.
Change SVG Color
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
$('img[src$=".svg"]').each(function () { | |
var $img = $(this), | |
imgID = $img.attr('id'), | |
imgClass = $img.attr('class'), | |
imgURL = $img.attr('src'); | |
$.get(imgURL, function (data) { | |
var $svg = $(data).find('svg'); | |
if (typeof imgID !== 'undefined') { | |
$svg = $svg.attr('id', imgID); | |
} | |
if (typeof imgClass !== 'undefined') { | |
$svg = $svg.attr('class', imgClass + ' replaced-svg'); | |
} | |
$svg = $svg.removeAttr('xmlns:a'); | |
if (!$svg.attr('viewBox') && $svg.attr('height') && $svg.attr('width')) { | |
$svg.attr('viewBox', '0 0 ' + $svg.attr('height') + ' ' + $svg.attr('width')) | |
} | |
$img.replaceWith($svg); | |
}, 'xml'); | |
}); |
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
svg { | |
path { | |
fill: #000; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment