Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CSS Selectors anchors: /mypage.html#anchor-select(#content > h1)
(function(window) {
function getSelector(hash) {
var matches;
hash = hash.slice(1);
matches = hash.match(/^anchor-select\((.+)\)$/);
if (matches) {
return decodeURIComponent(matches[1]);
}
return false;
}
function main(hash) {
var selector = getSelector(hash);
if (selector) {
window.document.querySelector(selector).scrollIntoView(true);
}
}
main(window.location.hash);
}(this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment