Skip to content

Instantly share code, notes, and snippets.

@palashmon
Created July 12, 2017 15:06
Show Gist options
  • Save palashmon/348daa5ecccaeafdcac9d692feabcabd to your computer and use it in GitHub Desktop.
Save palashmon/348daa5ecccaeafdcac9d692feabcabd to your computer and use it in GitHub Desktop.
bling dot js [updated]

This is a updated version of bling.js

We can used this with both querySelector($) and querySelectorAll($$)

Use Cases:

// classic qSA result with $$ + on()
$$('p').on('click', el => /* ... */);

// classic qS with $ + on()
$('#mydiv').on('click', el => /* ... */);
// based on https://gist.github.com/paulirish/12fb951a8b893a454b32
const $ = document.querySelector.bind(document);
const $$ = document.querySelectorAll.bind(document);
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((elem) => {
elem.on(name, fn);
});
};
export { $, $$ };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment