Created
February 24, 2024 12:52
-
-
Save hahwul/7c89b5308b99dbc86e8ae8273742043b to your computer and use it in GitHub Desktop.
Create Heading 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 createHeadingLinks(){ | |
const headings = document.querySelectorAll('h2[id],h3[id]'); | |
const linkContent = '#'; | |
for (const heading of headings) { | |
const linkIcon = document.createElement('a'); | |
linkIcon.setAttribute('href', `#${heading.id}`); | |
linkIcon.setAttribute('style', 'color: #aaa'); | |
linkIcon.innerHTML = linkContent; | |
heading.appendChild(linkIcon); | |
} | |
} | |
document.addEventListener('DOMContentLoaded', function () { | |
createHeadingLinks(); | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment