Created
September 5, 2018 07:25
-
-
Save goofmint/6e0e4005edc841166c947f845bea30d3 to your computer and use it in GitHub Desktop.
This file contains 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 $(selector, doc) { | |
let dom = null; | |
let target = doc || document; | |
const plural = !(selector.match(/^.*#[a-zA-Z0-9\-_\.]+$/)); | |
if (plural) { | |
dom = target.querySelectorAll(selector); | |
} else { | |
dom = target.querySelector(selector); | |
} | |
if (plural) { | |
if (dom.length > 0) return dom; | |
} else { | |
if (dom) return dom; | |
} | |
dom = document.createElement('div') | |
dom.$ = function(selector) { | |
return $(selector, dom) | |
}; | |
return plural ? [dom] : dom; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment