Created
August 10, 2015 13:13
-
-
Save lucasdidthis/6e7bdbd7633a2cc99208 to your computer and use it in GitHub Desktop.
replace every IMG-tag with the class ‘svg’ with the inline SVG from the linked file
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
jQuery('img.svg').each(function(){ | |
var $img = jQuery(this); | |
var imgID = $img.attr('id'); | |
var imgClass = $img.attr('class'); | |
var imgURL = $img.attr('src'); | |
jQuery.get(imgURL, function(data){ | |
var $svg = jQuery(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'); | |
$img.replaceWith($svg); | |
},'xml'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment