Created
July 18, 2017 11:18
-
-
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.
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
<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 + '">⚓</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