Skip to content

Instantly share code, notes, and snippets.

@adamjgrant
Last active March 24, 2024 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamjgrant/729db178d6b093dced5abfc16a59119f to your computer and use it in GitHub Desktop.
Save adamjgrant/729db178d6b093dced5abfc16a59119f to your computer and use it in GitHub Desktop.
Handy Functions
// 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