tags:

views:

34

answers:

3

I'm looking to get ideas on how to not change at all the code used to create css tabs (so that I can place it into an include file to avoid duplicating the code across all files that use it), but my current implementation doesn't allow this because I need to select the active tab using id="selectedTab".

The only implementation I found so far that solves this is the following one: http://unraveled.com/publications/css_tabs/

It requires assigning a class to each tab and uses the body id to determine the active tab.

Is this the only way or is there any other alternatives?

My current code looks like this (the id=noajax" is used to avoid using ajax to load certain pages):

<div class="productTabsBlock2">
  <a id="selectedTab" href="/link1" >OVERVIEW</a>
  <a href="/link2">SCREENSHOTS</a>
  <a id="noajax" href="/link3" >SPEED TESTS</a>
  <a href="/link4" >AWARDS</a>
</div>

EDIT: asp is available as server side and is already used on these pages.

A: 

An include file for what? If it's a server side programming language like PHP, you can pass a parameter for the selected tab through various methods.

Bart van Heukelom
Instead of duplicating the above code on all pages that share this tab code, I would prefer to use an include file so that it's easier to make any changes in the future.
smartins
Yes, you said that already ;)
Bart van Heukelom
+1  A: 

If you're looking for a non-JS solution, then the body class/id provide the easiest way to do what you want.

If you have access to JS library, you can easily add "selected" class to any of the <a> element and modify its appearance.

Just in case you haven't notice, you can use more than one class definition in an element. For example, <a class="noajax selected" /> is valid and both CSS selectors .noajax and .selected will be applied to the element.

Adrian Godong
Would it be possible to use a div instead of the body tag, something like this:<div class="selected" id="tab1"> <div class="productTabsBlock2"> <a class="tab1" href="/link1" >OVERVIEW</a> ....
smartins
As long as it is the parent of the <a> elements, yes it is possible.
Adrian Godong
A: 

you could use jQuery to add the `selectedTab' id (or class) like so

$('.productTabsBlock2 a').mouseover(function () {
  $(this).addClass('selectedTab');
});
pixeltocode
I would like to have a working non-JS version, I'm relying on ajax but if JS is not enabled then all the tabs will still work as expected.
smartins