Last active
March 24, 2024 00:31
-
-
Save adamjgrant/729db178d6b093dced5abfc16a59119f to your computer and use it in GitHub Desktop.
Handy Functions
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
// Name variables for their equivalent classnames. | |
// Assumes they have IDs with _ instead of -. | |
[].forEach((class_name) => { | |
const id_name = class_name.replace(/\-/g, '_'); | |
window[id_name] = document.getElementById(id_name); | |
}); | |
// Copy <templates> by ID. | |
const copy_from_template = (template_id) => document.getElementById(template_id).content.cloneNode(true).firstElementChild; | |
window.addEventListener('DOMContentLoaded', (event) => { | |
// DOM has loaded | |
}); | |
const $ = (selector) => Array.from(document.querySelectorAll(selector)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment