JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 6th, 2008, 08:04 PM
rxsid rxsid is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 221 rxsid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 13 h 43 m 33 sec
Reputation Power: 6
Question Change <a href> class type once selected?

Hi all,

Here's the basics on what I'm trying to do.

I've got three tabs, with the first one selected on page load. It has a 'selected' class that has a certain background color and text color. If the user clicks on one of the other tabs, I would like for that newly selected tab to now take on the 'selected' class attributes while the other two non active or non selected tabs have another class attributes.
Here's some of what I've got:

css
Code:
.tabs a{
float: left;
display: block;
font: bold 11px Arial;
color: white;
text-decoration: none;
margin: 0 1px 0 0; /*Margin between each menu item*/
padding: 5px 10px;
background-color: black;
border-top: 1px solid white;
}


.tabs a.selected{ /*currently selected tab*/
background-color: #7D9EC0;
color: white;
border-color: #7D9EC0;
}
.tabs a:hover{
background-color: #e8eff6;
color: #000000;
}




html
Code:
<div id="tabs" class="theClass">
<ul>
<li><a href="#" rel="tab1" class="selected" "onClick="displayHPTabContent('t1')">Tab 1</a></li>
<li><a href="#" rel="tab2" onClick="displayHPTabContent('t2')">Tab 2</a></li>
<li><a href="#" rel="tab3" onClick="displayHPTabContent('t3')">Tab 3</a></li>
</ul>
</div>


the javascript:
Code:
function displayHPTabContent(the_sub) {

if (the_sub == "t2") {
	document.getElementById('tab2').style.display = "";
	document.getElementById('tab1').style.display = "none";
	document.getElementById('tab3').style.display = "none";
} else if (the_sub == "t3") {
	document.getElementById('tab2').style.display = "none";
	document.getElementById('tab1').style.display = "none";
	document.getElementById('tab3').style.display = "";

document.getElementById('tab2').style.backgroundColor="yellow"; // **This is the part I'm not getting **
alert (document.getElementById('flowertabs').attributes);

} else if (the_sub == "t1") {
    document.getElementById('tab2').style.display = "none";
    document.getElementById('tab1').style.display = "";
 	document.getElementById('tab3').style.display = "none";
}

}


some more 'content' html below the tabs:
Code:
<div id="tab1">
stuff
</div>
<div id="tab2">
stuff
</div>
<div id="tab3">
stuff
</div>


My question is, how do I reference the 'rel' for the clicked on <a href> so that I can turn it's class to selected and make sure the others are
of the non selected class? Or, is there some other way?

Thanks!

Reply With Quote
  #2  
Old May 7th, 2008, 06:16 AM
PHP-Newb PHP-Newb is offline
Bad Coder
Click here for more information
 
Join Date: Jul 2003
Posts: 1,592 PHP-Newb User rank is First Lieutenant (10000 - 20000 Reputation Level)PHP-Newb User rank is First Lieutenant (10000 - 20000 Reputation Level)PHP-Newb User rank is First Lieutenant (10000 - 20000 Reputation Level)PHP-Newb User rank is First Lieutenant (10000 - 20000 Reputation Level)PHP-Newb User rank is First Lieutenant (10000 - 20000 Reputation Level)PHP-Newb User rank is First Lieutenant (10000 - 20000 Reputation Level)PHP-Newb User rank is First Lieutenant (10000 - 20000 Reputation Level)PHP-Newb User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 15 h 43 m
Reputation Power: 123
Ok, a quick example.
Javascript Code:
Original - Javascript Code
  1. <script type="text/javascript">
  2.   function init() {
  3.     var Links = document.getElementsByTagName('a');
  4.     for(var i=0; i<Links.length; i++) {
  5.       if(Links[i].className == 'aSelected' || Links[i].className == 'aUnselected') {
  6.         addEvent(Links[i], 'click', function(){displayHPTabContent(this.id)})
  7.       }
  8.     }
  9.   }
  10.  
  11.   function addEvent(obj, type, fn) {
  12.     if(obj.attachEvent) {
  13.       obj['e'+type+fn] = fn;
  14.       obj[type+fn] = function(){obj['e'+type+fn](window.event);}
  15.       obj.attachEvent('on'+type, obj[type+fn]);
  16.     }
  17.     else obj.addEventListener(type, fn, false);
  18.   }
  19.  
  20.   function displayHPTabContent(obj) {
  21.     var allObjs = document.getElementsByTagName('*');
  22.     for(var i=0; i<allObjs.length; i++) {
  23.       if(allObjs[i].className == 'aSelected') allObjs[i].className = 'aUnselected';
  24.       else if(allObjs[i].className == 'tabSelected') allObjs[i].className = 'tabUnselected';
  25.     }
  26.  
  27.     document.getElementById(obj).className = 'aSelected';
  28.     document.getElementById(obj+'t').className = 'tabSelected';
  29.   }
  30.  
  31.   window.onload = init;
  32. </script>
  33.  
HTML4Strict Code:
Original - HTML4Strict Code
  1. <a href="#" id="t1" class="aSelected">Tab 1</a>
  2. <a href="#" id="t2" class="aUnselected">Tab 2</a>
  3. <a href="#" id="t3" class="aUnselected">Tab 3</a>
  4.  
  5. <div id="t1t" class="tabSelected">Tab1</div>
  6. <div id="t2t" class="tabUnselected">Tab2</div>
  7. <div id="t3t" class="tabUnselected">Tab3</div>
  8.  
Comments on this post
rxsid agrees: excellent example given. thanks.
lnxgeek agrees!
__________________
Under no circumstances click the button, because it is pointless. Thanks!

Reply With Quote
  #3  
Old May 7th, 2008, 03:29 PM
rxsid rxsid is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 221 rxsid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 13 h 43 m 33 sec
Reputation Power: 6
excellent...thanks for the response and the suggestion PHP-Newb!

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Change <a href> class type once selected?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway