Skip to content

Instantly share code, notes, and snippets.

@toddmotto
Last active August 29, 2015 14:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toddmotto/e7fcdc18291060e2d2bc to your computer and use it in GitHub Desktop.
Save toddmotto/e7fcdc18291060e2d2bc to your computer and use it in GitHub Desktop.
104 bytes jQuery-like wrapper, $('.class') returns NodeList, $('.class:first') returns first Node only, optional scoping $('.class', '.parent')
function $(a,b){return(b||document)['querySelector'+(b=/\:first$/,b.test(a)?'':'All')](a.replace(b,''))}
@WebReflection
Copy link

if you don't have the array you don't have a jQuery like function …. I think it's not worth drop such feature, 134 bytes are still OK ;-)

edit thought it could have been smaller … well, you can go 103 using /:first$/ instead of /\:first$/

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