Skip to content

Instantly share code, notes, and snippets.

@rberenguel
Last active December 25, 2015 17:29
Show Gist options
  • Save rberenguel/7013658 to your computer and use it in GitHub Desktop.
Save rberenguel/7013658 to your computer and use it in GitHub Desktop.
A very poor man's HTML element selector. As much as I tried I couldn't fit it in a tweet, though. The best I could minify it has been to 154 bytes (as $$ below, it would be cool if it could be called ¢...)
function $(s){
z="getElement";n="Name";
a={"#" : z+"ById",
"." : z+"sByClass"+n,
}[s[0]];
a=typeof a==="undefined"?[z+"sByTag"+n,0]:[a,1];
return document[a[0]](s.slice(a[1]));
}
function $$(s){return S="slice",d=document,t=s[0],g="getElement",n="Name",t=="#"?d[g+"ById"](s[S](1)):t=="."?d[g+"sByClass"+n](s[S](1)):d[g+"sByTag"+n](s)}
@rberenguel
Copy link
Author

Knew it: everything is done under the sun ;) It was a fun afternoon hack at least. Mine looks far cruder, that's for sure!

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