treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Jquery Tab Effect & URLs

  • OK, jquery problem... I am creating a simple tabbed effect for a website. Click on a tab, the tab itself changes to an active state and the content below the tab changes. That is working quite well. What I would like to do though is link each tab to a specific url -- so, by visiting url.com/page.html#1 the visitor would see tab #1, url.com/page.html#2 would see tab #2, etc.

    Any ideas as to how I could go about that? (jQuery/javascript specific, I should add.) Not necessarily looking for specific code, just ways to approach the problem, or links to tutorials that might have done similar things.
  • Solved my own question... In case anyone else finds this useful, one approach is to use window.location.hash.

    <script type=\"text/javascript\">

    var pathname = window.location.hash;

    if ( pathname == \"#1\" ) {
    document.write(\"hash = 1\");
    }
    </script>