473,394 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

ARRRGH!

I have the following html. Each <td> has a class. onmouseover i'm
changing said class and I'm wondering if javascript can change the
class onclick, so that it stays a different color, and changes all the
other <td> classes so they're uncolored. Basically, i'm trying to turn
a tab a color when it is clicked, and change the other tabs back to
normal (in case another one has already been clicked).

Does this even make sense? I need a guru's help on this one!

<td class=table_tab onmouseover="this.className='table_tab_over'"
onmouseout="this.className='table_tab'">WELCOME</td>

<td class=table_tab onmouseover="this.className='table_tab_over'"
onmouseout="this.className='table_tab'">NOW HIRING</td>

<td class=table_tab onmouseover="this.className='table_tab_over'"
onmouseout="this.className='table_tab'">OUR TEAM</td>

Jul 23 '05 #1
2 1139
I'm willing to PAY for a response that works!

Leonardo wrote:
I have the following html. Each <td> has a class. onmouseover i'm
changing said class and I'm wondering if javascript can change the
class onclick, so that it stays a different color, and changes all the other <td> classes so they're uncolored. Basically, i'm trying to turn a tab a color when it is clicked, and change the other tabs back to
normal (in case another one has already been clicked).

Does this even make sense? I need a guru's help on this one!

<td class=table_tab onmouseover="this.className='table_tab_over'"
onmouseout="this.className='table_tab'">WELCOME</td>

<td class=table_tab onmouseover="this.className='table_tab_over'"
onmouseout="this.className='table_tab'">NOW HIRING</td>

<td class=table_tab onmouseover="this.className='table_tab_over'"
onmouseout="this.className='table_tab'">OUR TEAM</td>


Jul 23 '05 #2
"Leonardo" <le******@associatedcontent.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I have the following html. Each <td> has a class. onmouseover i'm
changing said class and I'm wondering if javascript can change the
class onclick, so that it stays a different color, and changes all the
other <td> classes so they're uncolored. Basically, i'm trying to turn
a tab a color when it is clicked, and change the other tabs back to
normal (in case another one has already been clicked).

Does this even make sense? I need a guru's help on this one!

<td class=table_tab onmouseover="this.className='table_tab_over'"
onmouseout="this.className='table_tab'">WELCOME</td>

<td class=table_tab onmouseover="this.className='table_tab_over'"
onmouseout="this.className='table_tab'">NOW HIRING</td>

<td class=table_tab onmouseover="this.className='table_tab_over'"
onmouseout="this.className='table_tab'">OUR TEAM</td>


<style type="text/css">
td.tab_over { background-color: Blue; }
td.tab { background-color: White; }
</style>
<script type="text/javascript">
var selectTab = function()
{
return false;
}
function findParentNode(node, name)
{
if (!node)
{
return null;
}

if (node.nodeName.toLowerCase() != name.toLowerCase())
{
node = findParentNode(node.parentNode, name);
}

return node;
}
</script>
<table id="myTabs">
<tr>
<td class="tab" onclick="selectTab(this);">WELCOME</td>
<td class="tab" onclick="selectTab(this);">NOW HIRING</td>
<td class="tab" onclick="selectTab(this);">OUR TEAM</td>
</tr>
</table>
<script type="text/javascript">
var table;
if (document.getElementById &&
(table = document.getElementById('myTabs')) &&
table.getElementsByTagName)
{
selectTab = function(cell)
{
var table = findParentNode(cell, 'table');

if (table)
{
var cells = table.getElementsByTagName('td');

var ii = cells.length;
while (ii-- > 0)
{
if (cells[ii] != cell)
{
cells[ii].className = 'tab';
}
else
{
cells[ii].className = 'tab_over';
}
}
}
}
}
</script>

A lot of the complexity of the code is simply there to determine whether
the table supports getElementByTagName(). If it does, then the function
that actually does the work gets assigned to -selectTab-.
Otherwise -selectTab- remains a "do nothing" function, thereby avoiding
having to test whether the table supports getElementsByTagName()
everytime the function is invoked and any possible errors that might
occur if the -onclick- event fires but -selectTab- weren't yet defined.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Larry Jaques | last post by:
I'm filling out forms on one page, then trying to send an email and print out the vars on the next page. Q1: Whenever I insert the mail script, it gives me a parse error. Please point out my...
23
by: JC | last post by:
I am very new to programming and learning on my own. Why do I keep getting duplicate values using this code? I want to shuffle a deck of 52 cards. The logic seems right to me. Randomize For...
0
by: Reply-to-group Thx | last post by:
Need to update col dated in tbl po_history from col date_expense in tbl po_expenses. Have tried, back ticks, single quotes, no quotes, etc. left join and no join. No joy. Results is consistent...
20
by: Terry | last post by:
I'm trying to have two divs side-by-side, each taking up 50% of the body. Sounds simple enough, right? http://novodom.net/div.html The code validates as XHTML 1.1 Strict. Looks fine in Firefox,...
383
by: John Bailo | last post by:
The war of the OSes was won a long time ago. Unix has always been, and will continue to be, the Server OS in the form of Linux. Microsoft struggled mightily to win that battle -- creating a...
3
by: dave | last post by:
ISBN 1-861000-88-X I'm confused about these references to the usage of recursion pertaining to example Ex6_08A: On page 236 in the last sentence of the 3rd paragraph "Since any set of...
2
by: Jonas Cord | last post by:
Hi, I'm trying to learn proxy classes in C++ so I've written the following code, trying to modify an example given in Deitel & Deitel's C++ book. I am trying to "hide" details of the original...
6
by: Tim Marshall | last post by:
Here's the situation. A form, frmSetUp, with a subform control called subExplain with a source object form frmSetUpSubDefineSides. The source object is a bound form, displaying a few records, no...
1
by: musosdev | last post by:
Hi guys I was using the Microsoft.Web.UI.WebControls extra namespace in my application to provide me with a TreeView control. I was using specifically ..GetNodeFromIndex(), SelectedNodeIndex and...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.