Skip to content

Instantly share code, notes, and snippets.

@confraria
Created May 7, 2020 18:56
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 confraria/be57a58d9844c3dc25e343d7a8d1b250 to your computer and use it in GitHub Desktop.
Save confraria/be57a58d9844c3dc25e343d7a8d1b250 to your computer and use it in GitHub Desktop.
h1 links
function addLinks() {
Array.from(document.querySelectorAll("[id]")).forEach((e) => {
const a = document.createElement("a");
a.href = `#${e.id}`;
e.parentNode.replaceChild(a, e);
a.appendChild(e);
});
}
if (document.readyState === "complete" || document.readyState === "loaded") {
addLinks();
} else {
window.addEventListener("DOMContentLoaded", addLinks);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment