Created
November 16, 2014 10:03
-
-
Save arkaitzgarro/bda0f0316eab18f742df to your computer and use it in GitHub Desktop.
DOM selector
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
var $ = function(selector) { | |
var elems; | |
// TODO: attach to Element prototipe | |
elems = document.querySelectorAll(selector); | |
if (elems && elems.length === 1) { | |
return elems[0]; | |
} else if (elems && elems.length > 1) { | |
return elems; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment