function convertImgSvg (img) { var svg_items = (typeof(img) == 'undefined')? $('img.svg') : img; var count = svg_items.length; var loaded = 0; svg_items.each(function () { var self = $(this); var imgID = self.attr('id'); var imgClass = self.attr('class'); var imgURL = self.attr('src'); $.get(imgURL, function (data) { var $svg = $(data).find('svg'); var $defs = $svg.children('defs') if ($defs.length) { $svg = $svg.html($defs.children()); } 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')) } self.replaceWith($svg); loaded++; if(loaded >= count){ $('body').trigger('svg-image-loaded'); } }, 'xml'); }); } $(document).ready(function(){ convertImgSvg(); });