Created
May 15, 2013 20:23
-
-
Save shiftycow/5587057 to your computer and use it in GitHub Desktop.
A simple example of Javascript powered tabs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script> | |
<script type="text/javascript"> | |
$(function(){ | |
console.log($(".tab")); | |
$(".tab").hide(); | |
$(".active").show(); | |
}); | |
function switchTab(tab) | |
{ | |
var newTab = $("#"+tab); | |
//hide the old tab | |
$(".active").hide(); | |
$(".active").removeClass("active"); | |
newTab.show(); | |
newTab.addClass("active"); | |
} | |
</script> | |
</head> | |
<body> | |
<ul> | |
<li><a onclick='switchTab("tab1")' style="cursor: pointer" >Tab 1</a></li> | |
<li><a onclick='switchTab("tab2")' style="cursor: pointer" >Tab 2</a></li> | |
</ul> | |
<div id="tab1" class="tab active"> | |
Tab 1 content | |
</div> | |
<div id="tab2" class="tab"> | |
Tab 2 content | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment