Last active
September 7, 2022 12:04
-
-
Save Ivannnnn/ff8b022f66a0e97811dc4c31dd95f0b0 to your computer and use it in GitHub Desktop.
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 $ = (q, container = document) => [...container.querySelectorAll(q)]; | |
$.createFragment = Range.prototype.createContextualFragment.bind( | |
document.createRange() | |
); | |
$.attr = (el, attrs) => { | |
for (let prop in attrs) { | |
HTMLElement.prototype.hasOwnProperty(prop) | |
? (el[prop] = attrs[prop]) | |
: el.setAttribute(prop, attrs[prop]); | |
} | |
}; | |
$.on = (el, events) => { | |
for (let name in events) el.addEventListener(name, events[name]); | |
}; | |
$.off = (el, events) => { | |
for (let name in events) el.removeEventListener(name, events[name]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment