Skip to content

Instantly share code, notes, and snippets.

@ddikman
Created July 18, 2017 11:18
Show Gist options
  • Save ddikman/4d9ae40affb06184a6eab3eda849e393 to your computer and use it in GitHub Desktop.
Save ddikman/4d9ae40affb06184a6eab3eda849e393 to your computer and use it in GitHub Desktop.
Small script to anchor headers on a page and highlight them if linked to.
<script type="text/javascript">
// add linked anchors to all the headers
jQuery("#content h1, #content h2, #content h3").each(function(e){
var header = jQuery(this);
var text = header.text();
var encodedId = text.replace(/[^A-Za-z\d]/g, '_');
header.attr("id", encodedId);
header.append('<a href="#' + encodedId + '">&#x2693;</a>');
});
if(window.location.hash.length > 0){
var hash = window.location.hash.substr(1);
jQuery('#' + hash).css("background-color", "Yellow");
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment