Well (although I suggested it) jQuery UI can be quite weighty. Bigger than jQuery its self.
If you only need simple tabs use this example. The extra JS is only 738 bytes.
HTML Code:
<div id="navigationContainer">
<ul class="listContainer">
<li class="panel"><a href="#panel1">Panel 1</a></li>
<li class="panel"><a href="#panel2">Panel 2</a></li>
<li class="panel"><a href="#panel3">Panel 3</a></li>
<li class="panel"><a href="#panel4">Panel 4</a></li>
</ul>
</div>
<div id="wrapper">
<div id="content">
<div id='panel1' class='panel'>Content of panel 1 goes here...</div>
<div id='panel2' class='panel'>Content of panel 2 goes here...</div>
<div id='panel3' class='panel'>Panel 3 goes here...</div>
<div id='panel4' class='panel'>Panel 4 is last <em>and</em> least. It’s crap.</div>
</div>
</div>
Code JavaScript:
<script type="text/javascript">
var panels = {
init : function() {
if(!$('#navigationContainer')[0]) {
return;
}
//Show only first panel
panels.hideAll();
$('#content .panel:nth-child(1)').removeClass('hidden');
//Tab clicks
$('#navigationContainer').delegate('a', 'click', panels.tabClick);
},
hideAll : function() {
$('#content .panel').addClass('hidden');
},
tabClick : function(ev) {
ev.preventDefault();
var href = ev.currentTarget.href;
//array of matches. [0] will be like #panel2
var panel_id = href.match(/#(.+)$/);
if(!panel_id) {
return;
}
panels.hideAll();
$(panel_id[0]).removeClass('hidden'); //show correct panel
}
};
$(document).ready(panels.init);
</script>
You'll need to define the .hidden class in your CSS for this to work.
Also, I fixed up your markup. You have multiple elements with the ID of panel1 and no = sign before your href.
Bookmarks