Skip to content

Instantly share code, notes, and snippets.

@kathgironpe
Created March 25, 2014 12:48
Show Gist options
  • Save kathgironpe/9761174 to your computer and use it in GitHub Desktop.
Save kathgironpe/9761174 to your computer and use it in GitHub Desktop.
;(function(w, d, undefined){
'use strict';
var $ = function (e) {
var firstChar = e.charAt(0);
if (firstChar === '#') {
return d.querySelector(e);
} else if (firstChar === '.') {
return d.querySelectorAll(e);
} else {
return d.getElementById(e);
}
};
// add to window
w.$ = $;
})(window, document);
console.log($('#my-element')); // querySelector()
console.log($('.my-element')); // querySelectorAll()
console.log($('my-element')); // getElementById()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment