Skip to content

Instantly share code, notes, and snippets.

@lucasdidthis
Created August 10, 2015 13:13
Show Gist options
  • Save lucasdidthis/6e7bdbd7633a2cc99208 to your computer and use it in GitHub Desktop.
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
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