Last active
December 25, 2015 17:29
-
-
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 ¢...)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)} |
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
Check this out: https://gist.github.com/jed/991057