Created
March 26, 2025 19:55
-
-
Save pattonwebz/ab9126393791742dea9f67d63dcfb5f7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| document.addEventListener("DOMContentLoaded", function () { | |
| /* | |
| * Find any insteances of the selector in oldTag and replace it with the tag from newTag. | |
| */ | |
| function replaceHeadingLevel(oldTag, newTag) { | |
| document.querySelectorAll(oldTag).forEach(function (element) { | |
| var newHeading = document.createElement(newTag); | |
| newHeading.innerHTML = element.innerHTML; | |
| // Copy attributes from old heading to new heading. | |
| Array.from(element.attributes).forEach(attr => { | |
| newHeading.setAttribute(attr.name, attr.value); | |
| }); | |
| element.replaceWith(newHeading); | |
| }); | |
| } | |
| // Change all H2s inside blog posts to H3s. | |
| replaceHeadingLevel(".post-content h2", "h3"); | |
| // Change all H4s to H2s. | |
| replaceHeadingLevel(".post-content h4", "h2"); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment