Created
May 7, 2011 10:15
-
-
Save metamn/960384 to your computer and use it in GitHub Desktop.
Create TOC on the fly
This file contains hidden or 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
// Creating TOC | |
var toc = jQuery(".page #article #body .body > :header:not(h3,h4,h5,h6)"); | |
if ( toc.size() > 0) { | |
jQuery(".page #article #aside #toc").removeClass('hidden'); | |
var res = "<ul>"; | |
toc.each(function(index) { | |
var ref = " id" + index; | |
var id = jQuery(this).attr("id"); | |
jQuery(this).attr("id", id + ref); | |
res = res + "<li><a href='#" + ref + "'>" + this.innerHTML + '</a></li>'; | |
}); | |
res += "</ul>"; | |
jQuery(".page #article #aside #toc").append(res); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment