Skip to content

Instantly share code, notes, and snippets.

@CodeZeno
CodeZeno / elements.js
Created June 29, 2020 05:29
Javascript - Attach functions to array of elements returned by a selector
const $ = function(selector) {
return new $.elements(Array.from(document.querySelectorAll(selector)));
}
$.elements = function(elements) {
this.html = function(text) {
elements.map((element) => element.innerHTML = text);
};
this.load = async function(filePath) {
this.html(await (await fetch(filePath)).text());
};