Skip to content

Instantly share code, notes, and snippets.

@brittanydionigi
Created July 9, 2019 14:20
Show Gist options
  • Save brittanydionigi/c2bb16b0ceb16e5d397b099ab454daea to your computer and use it in GitHub Desktop.
Save brittanydionigi/c2bb16b0ceb16e5d397b099ab454daea to your computer and use it in GitHub Desktop.
little pretend jQuery
function $(selector) {
function selectWithJS() {
let selectorType = selector.split('').shift();
let selectorName = selector.substr(1);
if (selectorType === '#') {
return document.getElementById(selectorName);
} else {
return document.querySelectorAll(selectorName);
}
}
return {
addClass(className) {
if (selector.includes('#')) {
document.getElementById('foo').classList.add(className);
} else {
document.querySelectorAll('foo').classList.add(className);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment