Skip to content

Instantly share code, notes, and snippets.

@JTRNS
Created September 25, 2021 11:15
Show Gist options
  • Save JTRNS/571383ec963ff6155a8ee4cba52aef5b to your computer and use it in GitHub Desktop.
Save JTRNS/571383ec963ff6155a8ee4cba52aef5b to your computer and use it in GitHub Desktop.
A more shiny variation of the popular bling dot js
/* blingbling.js */
window.$ = document.querySelector.bind(document);
window.$$ = document.querySelectorAll.bind(document);
HTMLElement.prototype.$ = function (selector) {
return this.querySelector(selector);
}
HTMLElement.prototype.$$ = function (selector) {
return this.querySelectorAll(selector);
}
Node.prototype.on = window.on = function (name, fn) {
this.addEventListener(name, fn);
}
NodeList.prototype.__proto__ = Array.prototype;
NodeList.prototype.on = NodeList.prototype.addEventListener = function (name, fn) {
this.forEach(function (elem, i) {
elem.on(name, fn);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment