Skip to content

Instantly share code, notes, and snippets.

@insom
Created May 25, 2014 22: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 insom/0070d6dd9c3d18f3c8db to your computer and use it in GitHub Desktop.
Save insom/0070d6dd9c3d18f3c8db to your computer and use it in GitHub Desktop.
Add ASCII-art underlines to H2's
// Happy "I can copy and paste and write enough JavaScript to get the thing that I wanted to do done" Day
// - Aaron
String.prototype.repeat = function(times) {
return (new Array(times + 1)).join(this);
}; // from http://stackoverflow.com/questions/4549894/how-can-i-repeat-strings-in-javascript
function insertAfter(referenceNode, newNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}; // from http://stackoverflow.com/questions/4793604/how-to-do-insert-after-in-javascript-without-using-a-library
var h2s = document.getElementsByTagName("h2");
for(i = 0; i < h2s.length; i++) {
var e = document.createElement("p");
e.style.marginBottom = '1.7em';
e.innerText = '='.repeat(h2s[i].innerText.length);
insertAfter(h2s[i], e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment