hugo-batsite/public/js/headings.js
2022-04-15 21:22:33 +02:00

13 lines
406 B
JavaScript

(function addHeadingLinks() {
var article = document.getElementById("content");
var headings = article.querySelectorAll("h1, h2, h3, h4, h5, h6");
headings.forEach(function (heading) {
if (heading.id) {
var a = document.createElement("a");
a.innerHTML = heading.innerHTML;
a.href = "#" + heading.id;
heading.innerHTML = "";
heading.appendChild(a);
}
});
})();