Skip to content

Instantly share code, notes, and snippets.

@madrobby
Created July 29, 2012 19:50
Show Gist options
  • Save madrobby/3201472 to your computer and use it in GitHub Desktop.
Save madrobby/3201472 to your computer and use it in GitHub Desktop.
Check if the browsers supports SVG
// comments welcome, there may be better ways to do this!
function supportsSVG(){
return !!('createElementNS' in document &&
document.createElementNS('http://www.w3.org/2000/svg','svg').createSVGRect)
}
@madrobby
Copy link
Author

I'm looking for an as-short-as-possible snippet that reliably detects support for SVG.

@Hugosslade
Copy link

You can crunch this down a bit to be

function supportsSVG(a,b){return !!((b='createElementNS') in (a=document) && a[b]('http://www.w3.org/2000/svg','svg').createSVGRect)}

Which saves 9 bytes - if that's what you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment