Created
May 7, 2020 18:56
-
-
Save confraria/be57a58d9844c3dc25e343d7a8d1b250 to your computer and use it in GitHub Desktop.
h1 links
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
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