Created
May 25, 2014 22:13
-
-
Save insom/0070d6dd9c3d18f3c8db to your computer and use it in GitHub Desktop.
Add ASCII-art underlines to H2's
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
// 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