Convert .SVG image

Below is script to convert svg image from img tag to SVG tag. After converting image in svg tag you can able to fill color in that image.

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');
});

No comments

Leave a Reply

Your email address will not be published. Required fields are marked *