Created
February 14, 2023 14:13
-
-
Save Nolwennig/05a903a49cff58d9320e289d61c3008c to your computer and use it in GitHub Desktop.
color each h2-h6 from DOM with a dotted border
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
let headings = document.querySelectorAll('h2, h3, h4, h5, h6'); | |
for (let i = 0; i < headings.length; i++) { | |
let heading = headings[i]; | |
let level = parseInt(heading.tagName.charAt(1)); | |
let color; | |
switch (level) { | |
case 2: | |
color = "red"; | |
break; | |
case 3: | |
color = "orange"; | |
break; | |
case 4: | |
color = "yellow"; | |
break; | |
case 5: | |
color = "green"; | |
break; | |
case 6: | |
color = "blue"; | |
break; | |
default: | |
color = "black"; | |
} | |
heading.style.border = "1px dotted " + color; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment