Monday, 22 April 2019

embed an SVG and change its color in CSS without using a JS-SVG framework?


embed an SVG and change its color in CSS without using a JS-SVG framework?

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) { // Get the SVG tag, ignore the rest 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:

Post a Comment

remove a property from a JavaScript object?

remove a property from a JavaScript object? delete myObject.regex; // or, delete myObject['regex']; // or, var prop = ...