Skip to content

Instantly share code, notes, and snippets.

@Nolwennig
Created February 14, 2023 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nolwennig/05a903a49cff58d9320e289d61c3008c to your computer and use it in GitHub Desktop.
Save Nolwennig/05a903a49cff58d9320e289d61c3008c to your computer and use it in GitHub Desktop.
color each h2-h6 from DOM with a dotted border
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