Created
February 10, 2010 16:12
-
-
Save eyeseast/300476 to your computer and use it in GitHub Desktop.
JavaScript to add paragraph-level permalinks to some HTML
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
function permalinks(id) { | |
var entry = document.getElementById(id); | |
var paras = entry.getElementsByTagName('p'); | |
for (var i=0; i < paras.length; i++) { | |
var p = paras[i]; | |
p.id = 'p' + i; | |
var a = document.createElement('a'); | |
a.href = '#p' + i; | |
a.title = 'Link to this paragraph'; | |
a.appendChild(document.createTextNode(' #')); | |
p.appendChild(a); | |
}; | |
}; | |
window.addEventListener('load', function() { | |
permalinks('entry-text'); | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment