Skip to content

Instantly share code, notes, and snippets.

@CodeZeno
CodeZeno / elements.js
Created Jun 29, 2020
Javascript - Attach functions to array of elements returned by a selector
View elements.js
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());
};