Skip to content

Instantly share code, notes, and snippets.

@goofmint

goofmint/index.js

Created Sep 5, 2018
Embed
What would you like to do?
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