Menu
Helooooo nice people!
Please help me as I am newbish …
I have a table as a menu and I want the table background color to change as the user clicks a link in each table cell sort of like tabs.
Can I do this client side with Javascript ot DHTML ???
?
I want the onclick event to change the background color of that cell to white while the rest remain grey.[/QUOTE]
<i>
</i>var ele = this.parentNode;
while(ele.tagName!="TD") {
ele = ele.parentNode;
}
ele.style.backgroundColor = "white";
[code=php]
<script type="text/javascript">
var cells;
function changeC(c){
for(var i=0;i<cells.length;i++){
cells[i].style.backgroundColor=(cells[i]==c)?'#ffffff':'';
}
}
onload=function(){
cells=document.getElementById('table3').getElementsByTagName('td');
for(var i=0;i<cells.length;i++){
cells[i].onclick=function(){changeC(this)}
}
}
</script>
[/code]
[code=html]<a href="#" onclick="this.parentNode.style.backgroundColor='white'; ">Blah</td>[/code]
[code=html]<td><a href="#" onclick="this.parentNode.style.backgroundColor='white'>Blah</td>[/code]
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
var cells;
function changeC(c){
for(var i=0;i<cells.length;i++){
cells[i].style.backgroundColor=(cells[i]==c)?'#ffffff':'';
}
}
onload=function(){
cells=document.getElementById('table3').getElementsByTagName('td');
for(var i=0;i<cells.length;i++){
cells[i].onclick=function(){changeC(this)}
}
}
</script>
</head>
<body>
<table border="1" width="100%" id="table3" bgcolor="#808080" bordercolorlight="#000000" bordercolordark="#000000" style="border-collapse: collapse">
<tr>
<td align="center" nowrap><b><font size="5"><a href="Intro.htm" onclick >Home</a></font></b></td>
<td align="center" nowrap><b><font size="5"><a href="resume.htm">Resume</a></font></b></td>
<td align="center" nowrap><b><font size="5"><a href="work.htm">Work History</a></font></b></td>
<td align="center" nowrap><b><font size="5"><a href="interests.htm">Interests</a></font></b></td>
<td align="center" nowrap><b><font size="5"><a href="picture.htm">Pictures</a></font></b></td>
<td align="center" nowrap><b><font size="5"><a href="contact.htm">Contact Me</a></font></b></td>
</tr>
</table>
</body>
</html>
[/code]
0.1.9 — BETA 6.17