Skip to content

Instantly share code, notes, and snippets.

@adamkudrna
Last active August 31, 2015 14:29
Show Gist options
  • Save adamkudrna/0ee60ea24ee4c780fc10 to your computer and use it in GitHub Desktop.
Save adamkudrna/0ee60ea24ee4c780fc10 to your computer and use it in GitHub Desktop.
SVG src fallback by Jobs UI
/*
* Replaces SVG images in img elements with PNG alternative
*
* The PNG file must have the same URL as the SVG file, up to the extension.
*/
$(function () {
'use strict';
function supportsSvg() {
return document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#Image', '1.1');
}
if (!supportsSvg()) {
$('img[src$=".svg"], img[src*=".svg?"]').attr('src', function (i, src) {
return src.replace(/\.svg(\?|$)/, '.png$1');
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment