Created
July 9, 2019 14:20
-
-
Save brittanydionigi/c2bb16b0ceb16e5d397b099ab454daea to your computer and use it in GitHub Desktop.
little pretend jQuery
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) { | |
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