Forum Moderators: open

Message Too Old, No Replies

jQuery Tabs how to have all other tabs retract on page load

         

cyberpunkstudio

9:53 am on Jan 7, 2010 (gmt 0)

10+ Year Member



Hi I followed a tutorial at <snipped URL>. The tutorial works fine however once I have implemented it onto my own website when the page loads all three tabs with their content in the div are displayed once the page has completly loaded the other tabs dissappear how do I make it so that on default the other unselected tabs do not appear and are contradted?


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Tabs</title>
<style type="text/css" media="screen">
<!--
BODY { margin: 10px; padding: 0; font: 1em "Trebuchet MS", verdana, arial, sans-serif; font-size: 100%; }
H1 { margin-bottom: 2px; font-family: Garamond, "Times New Roman", Times, Serif;}
DIV.container { margin: auto; width: 90%; margin-bottom: 10px;}
TEXTAREA { width: 80%;}
FIELDSET { border: 1px solid #ccc; padding: 1em; margin: 0; }
LEGEND { color: #ccc; font-size: 120%; }
INPUT, TEXTAREA { font-family: Arial, verdana; font-size: 125%; padding: 7px; border: 1px solid #999; }
LABEL { display: block; margin-top: 10px; }
IMG { margin: 5px; }

UL.tabNavigation {
list-style: none;
margin: 0;
padding: 0;
}

UL.tabNavigation LI {
display: inline;
}

UL.tabNavigation LI A {
padding: 3px 5px;
background-color: #ccc;
color: #000;
text-decoration: none;
}

UL.tabNavigation LI A.selected,
UL.tabNavigation LI A:hover {
background-color: #333;
color: #fff;
padding-top: 7px;
}

UL.tabNavigation LI A:focus {
outline: 0;
}

div.tabs > div {
padding: 5px;
margin-top: 3px;
border: 5px solid #333;
}

div.tabs > div h2 {
margin-top: 0;
}

#first {
background-color: #f00;
}

#second {
background-color: #0f0;
}

#third {
background-color: #00f;
}

.waste {
min-height: 1000px;
}
-->
</style>

<script src="js/jquery.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(function () {
var tabContainers = $('div.tabs > div');
tabContainers.hide().filter(':first').show();

$('div.tabs ul.tabNavigation a').click(function () {
tabContainers.hide();
tabContainers.filter(this.hash).show();
$('div.tabs ul.tabNavigation a').removeClass('selected');
$(this).addClass('selected');
return false;
}).filter(':first').click();
});
</script>

</head>
<body id="page">
<div class="tabs">
<ul class="tabNavigation">
<li><a href="#first">First</a></li>
<li><a href="#second">Second</a></li>
<li><a href="#third">Third</a></li>
</ul>

<div id="first">
<h2>First</h2>
<a href="http://www.google.com">dolor sit amet</a>
<a href="http://www.google.com">dolor sit amet</a>
<a href="http://www.google.com">dolor sit amet</a>
<a href="http://www.google.com">dolor sit amet</a>
<a href="http://www.google.com">dolor sit amet</a>
<a href="http://www.google.com">dolor sit amet</a>
</div>
<div id="second">

<h2>Second</h2>
<a href="http://www.google.com">dolor sit amet</a>
<a href="http://www.google.com">dolor sit amet</a>
<a href="http://www.google.com">dolor sit amet</a>
<a href="http://www.google.com">dolor sit amet</a>
<a href="http://www.google.com">dolor sit amet</a>
<a href="http://www.google.com">dolor sit amet</a>
</div>
<div id="third">
<h2>Third</h2>
<a href="http://www.google.com">dolor sit amet</a>
<a href="http://www.google.com">dolor sit amet</a>
<a href="http://www.google.com">dolor sit amet</a>
<a href="http://www.google.com">dolor sit amet</a>
<a href="http://www.google.com">dolor sit amet</a>
<a href="http://www.google.com">dolor sit amet</a>
</div>
</div>
<div class="waste"></div>
</body>

</html>

Hope you can help, or if you know of any othe javascript source that is easy to implement to create tabs will be appreciated

Thanks

[edited by: whoisgregg at 5:38 pm (utc) on Jan. 7, 2010]
[edit reason] Whoops, no URLs please. See TOS [webmasterworld.com] :) [/edit]

whoisgregg

10:20 pm on Feb 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For the non-default tabs, you can define their style to be hidden in the CSS. However, this means users with Javascript disabled won't be able to see that content at all. Something like:

<div id="third" style="display: none;">