Created
January 11, 2020 07:31
-
-
Save krutoo/d64fbd0e5f2e0f1b4d19a9c2e27f1cff to your computer and use it in GitHub Desktop.
DOM shortcut utils
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
export const $ = selectors => document.querySelector(selectors); | |
export const $$ = selectors => document.querySelectorAll(selectors); | |
// on(div, 'click touch', () => {}); | |
export const on = (target, eventNames, handler, options) => { | |
const eventNamesList = eventNames.split(' '); | |
eventNamesList.forEach(eventName => { | |
target.addEventListener(eventName, handler, options); | |
}); | |
return () => { | |
eventNamesList.forEach(eventName => { | |
target.removeEventListener(eventName, handler, options); | |
}); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment