Skip to content

Instantly share code, notes, and snippets.

@wmoxam
Created May 18, 2010 15:56
Show Gist options
  • Save wmoxam/405151 to your computer and use it in GitHub Desktop.
Save wmoxam/405151 to your computer and use it in GitHub Desktop.
<div class="tab" id="main">
<a href="http://yadda.ya/foo#main">Main</a>
...
</div>
<div class="tab" id="other">
a href="http://yadda.ya/foo#other">Other</a>
...
</div>
.. etc ..
function switch_to_tab()
{
var hash = document.location.hash;
var name = (typeof hash == 'string') ? hash.gsub('#', '') : '';
if(name == '') return;
$$('.tab').each(function(tab) {
if(tab.id == name)
tab.show();
} else {
tab.hide();
}
}
}
document.observe('dom:loaded', switch_to_tab);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment