Skip to content

Instantly share code, notes, and snippets.

@weaming
Last active March 31, 2016 10:16
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 weaming/7e6cea5f484bb4be2587 to your computer and use it in GitHub Desktop.
Save weaming/7e6cea5f484bb4be2587 to your computer and use it in GitHub Desktop.
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
if ($("#toc").length == 0){
console.log('#toc not found.');
return 1;
}
$("h2,h3,h4,h5,h6").each(function(i,item){
var tag = $(item).get(0).localName;
$(item).attr("id","toc"+i);
$("#toc").append('<a class="toc'+tag+'" href="#toc'+i+'">'+$(this).text()+'</a></br>');
$(".toch2").css("margin-left",0);
$(".toch3").css("margin-left",20);
$(".toch4").css("margin-left",40);
$(".toch5").css("margin-left",60);
$(".toch6").css("margin-left",80);
});
});
</script>
<div id="toc"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment