Skip to content

Instantly share code, notes, and snippets.

@joacim-boive
Forked from icodeforlove/gist:868532
Created April 27, 2011 06:08
Show Gist options
  • Save joacim-boive/943793 to your computer and use it in GitHub Desktop.
Save joacim-boive/943793 to your computer and use it in GitHub Desktop.
querySelectorAll for anything less than IE8
// IE7 support for querySelectorAll in 226 bytes... It's a little slow but better than a 20kb solution when you need something cross platform and lightweight.
(function(d){d=document,a=d.styleSheets[0]||d.createStyleSheet();d.querySelectorAll=function(e){a.addRule(e,'f:b');for(var l=d.all,b=0,c=[],f=l.length;b<f;b++)l[b].currentStyle.f&&c.push(l[b]);a.removeRule(0);return c}})()
@bronzehedwick
Copy link

Script looks very promising, but I can't seem to get it to work :(
Running it out of the box in IE7 throws

SCRIPT438: Object doesn't support property or method 'querySelectorAll' 

Running the script through http://JSHint.com also threw errors, but I'm too green to know if that matters.

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