Skip to content

Instantly share code, notes, and snippets.

View greg-raven's full-sized avatar

Greg Raven greg-raven

View GitHub Profile
@greg-raven
greg-raven / loadHtml.js
Created September 3, 2022 11:59
Vanilla JavaScript AJAX code for loading external HTML fragments
/*
* Replicates the functionality of jQuery's `load` function,
* used to load some HTML from another file into the current one.
*
* My version of this Stack Overflow answer:
* https://stackoverflow.com/a/38132775/3626537
* And `fetch` documentation:
* https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch
*
* @param {string} parentElementId - The ID of the DOM element to load into
@greg-raven
greg-raven / addClass.js
Created September 3, 2022 11:54
Vanilla JavaScript addClass
function addClass(elements, myClass) {
// if there are no elements, we're done
if (!elements) {
return;
}
// if we have a selector, get the chosen elements
if (typeof elements === "string") {
elements = document.querySelectorAll(elements);
}
@greg-raven
greg-raven / keybase.md
Created December 12, 2016 12:50
Keybase proof

Keybase proof

I hereby claim:

  • I am greg-raven on github.
  • I am gregraven (https://keybase.io/gregraven) on keybase.
  • I have a public key ASBbQizbj8pLP6_BHUHv3DmF17LQdQQjU7wXX9WtXifrTQo

To claim this, I am signing this object: