SVG Test

Tests are borrowed from Modernizr. Add/Remove body class function is custom.

by napotopia

JavaScript

$(function(){
    
    // Stolen from Modernizr
    
    var ns = {'svg': 'http://www.w3.org/2000/svg'},
        tests = {};
    
    // Thanks to Erik Dahlstrom
    tests['svg'] = function() {
        return !!document.createElementNS && !!document.createElementNS(ns.svg, 'svg').createSVGRect;
    };

    // specifically for SVG inline in HTML, not within XHTML
    // test page: paulirish.com/demo/inline-svg
    tests['inlinesvg'] = function() {
      var div = document.createElement('div');
      div.innerHTML = '<svg/>';
      return (div.firstChild && div.firstChild.namespaceURI) == ns.svg;
    };
    
    $.each(tests, function(i, val) {
        if (this.call()) {
            $('body').addClass(i);
        } else {
            $('body').addClass('no-' + i);
        }
    });    

});