Skip to content

Instantly share code, notes, and snippets.

@goofmint
Created September 5, 2018 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goofmint/6e0e4005edc841166c947f845bea30d3 to your computer and use it in GitHub Desktop.
Save goofmint/6e0e4005edc841166c947f845bea30d3 to your computer and use it in GitHub Desktop.
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