Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 13:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
dropAnchor() - Secondary anchor `scrollIntoView()-er` for featured listings on a homepage
function dropAnchor(str) { // Eh...
var hash = str || window.location.hash || location.pathname.match(/\/features\/(.*)/)[1];
var links = document.getElementsByTagName('a');
var anchors = [];
for (var i in links) {
var name = links[i].name;
if (name) anchors.push(links[i]);
if (hash) {
for (var i in anchors) {
var regex = new RegExp(hash.replace('#', ''), "i");
if (anchors[i].name.match(regex)) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment