Skip to content

Instantly share code, notes, and snippets.

@ITJoePC
Forked from AllThingsSmitty/querySelector.js
Created November 8, 2017 21:09
Show Gist options
  • Save ITJoePC/eb0080848e5c4e4ef58335230e26db54 to your computer and use it in GitHub Desktop.
Save ITJoePC/eb0080848e5c4e4ef58335230e26db54 to your computer and use it in GitHub Desktop.
Use querySelector with .bind() as a shortcut to familiar function names
// returns first element selected - $('input[name="food"]')
var $ = document.querySelector.bind(document);
// return array of selected elements - $$('img.dog')
var $$ = document.querySelectorAll.bind(document);
// Credit: https://twitter.com/wesbos/status/608341616173182977
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment