Skip to content

Instantly share code, notes, and snippets.

@arkokoley
Last active December 22, 2015 02:28
Show Gist options
  • Save arkokoley/6403456 to your computer and use it in GitHub Desktop.
Save arkokoley/6403456 to your computer and use it in GitHub Desktop.
JS script to anchor all h2 tags.
function addAnchors(){
//loop through all your headers
$.each($('h3'),function(index,value){
//append the text of your header to a list item in a div, linking to an anchor we will create on the next line
$('#box-anchors').append('<li><a href="#anchor-'+index+'">'+$(this).html()+'</a></li>');
//add an a tag to the header with a sequential name
$(this).wrapInner('<a name="anchor-'+index+'">'+$(this).html()+'</a>');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment