Skip to content

Instantly share code, notes, and snippets.

@marijnh
Created October 21, 2016 10:23
Show Gist options
  • Save marijnh/e476c561a1c6b02ea175fd400e028219 to your computer and use it in GitHub Desktop.
Save marijnh/e476c561a1c6b02ea175fd400e028219 to your computer and use it in GitHub Desktop.
Check a page for dangling links to local anchors
let links = document.querySelectorAll("a[href]")
let base = /^[^#]*/.exec(document.location)[0] + "#"
for (let i = 0; i < links.length; i++) {
let link = links[i], anchor
if (link.href.indexOf(base) == 0 && !document.getElementById(anchor = decodeURIComponent(link.href.slice(base.length))))
console.log("Missing anchor: " + anchor)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment