Skip to content

Instantly share code, notes, and snippets.

@gotoplanb
Created November 1, 2011 02:15
Show Gist options
  • Save gotoplanb/1329658 to your computer and use it in GitHub Desktop.
Save gotoplanb/1329658 to your computer and use it in GitHub Desktop.
Strip the URL after a hash in order to do animation on single-page website.
// Strip the URL after a hash in order to do animation on single-page website.
// Should be replaced with $(this).attr('href')
var urlClicked = "http://smartmediacreative.com/index.php#optimize";
// Loop throught the href to find the hash.
var counter = 0;
while (urlClicked[counter] !== '#') {
counter += 1;
}
// Slice the href from hash to end to keep the ID of the div that should become active.
var activeDiv = urlClicked.slice(counter + 1);
// Alert as diagnostic
alert(activeDiv);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment