Last active
October 27, 2021 00:08
-
-
Save AaronLayton/23e727b6f6b2fb84a119a36384a521e8 to your computer and use it in GitHub Desktop.
quick DOM helper
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
const $ = (selector) => { | |
const helper = { | |
version: '0.0.1' | |
}; | |
helper._elms = document.querySelectorAll(selector); | |
gf | |
const processArray = cb => helper._elms.forEach(cb); | |
helper.on = (event, callback) => { | |
processArray(elm => elm.addEventListener(event, callback)); | |
}; | |
helper.addClass = (cssClass) => { | |
processArray(elm => elm.classList.add(cssClass)); | |
}; | |
helper.removeClass = (cssClass) => { | |
processArray(elm => elm.classList.remove(cssClass)); | |
}; | |
helper.toggleClass = (cssClass) => { | |
processArray(elm => elm.classList.toggle(cssClass)); | |
}; | |
return helper; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment