Skip to content

Instantly share code, notes, and snippets.

@antimatter15
Created February 27, 2010 18:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save antimatter15/316861 to your computer and use it in GitHub Desktop.
Save antimatter15/316861 to your computer and use it in GitHub Desktop.
//Partial Implemenation CSS 2.1 Selectors in 500 bytes
function QSA(s){var p=[document.documentElement];(" "+s).replace(/ *([\>\+]) */g,"$1;%").replace(/ ([\.\#\:])/g," *$1").replace(/([ \%\.\#\:\>\+\[]|^)(;\% .+?\]|;|[^\[\.\#\:\>\+\% ]*)/g,function(z,o,a){for(var i=0,n=[],c;i<p.length;i++){c=p[i];c.nodeType==1&&(n=n.concat([].slice.call(eval({" ":'c.getElementsByTagName(a||"*")',">":"c.childNodes","+":"c.nextSibling","%":"c.tagName&&c.tagName.toLowerCase()==a.toLowerCase()?[c]:[]",".":'(" "+c.className+" ").indexOf(" "+a+" ")<0?[]:[c]',"#":"c.id==a?[c]:[]"}[o]))))}p=n});return p};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment