Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Modernizr snippet to replace all the image sources with PNG if there is no support for SVG
if (!Modernizr.svg) {
// wrap this in a closure to not expose any conflicts
(function() {
// grab all images. getElementsByTagName works with IE5.5 and up
var imgs = document.getElementsByTagName('img'),endsWithDotSvg = /.*\.svg$/,i = 0,l = imgs.length;
// quick for loop
for(; i < l; ++i) {
if(imgs[i].src.match(endsWithDotSvg)) {
// replace the png suffix with the svg one
imgs[i].src = imgs[i].src.slice(0, -3) + 'png';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.