[Javascript] tab kleur vastzetten na Onclick

Pagina: 1
Acties:

  • klaaz
  • Registratie: April 2000
  • Laatst online: 24-04 16:54

klaaz

it's me!

Topicstarter
Ik heb de volgende code gebouwd om d.m.v. tabs een pagina inhoud te kunnen wijzigen:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<script language="javascript">
showRow = (navigator.appName.indexOf("Internet Explorer") != -1) ? "block" : "table-row";

function flipCell(countt){
  a = document.getElementById("taalnl"); 
  b = document.getElementById("taalde"); 
     
if (countt == 1){
  a.style.display = (a.style.display == "block") ? showRow : "block";
  b.style.display = "none";
  }
if (countt == 2){
  a.style.display = "none";
  b.style.display = (b.style.display == "block") ? showRow : "block";
  }
}
</script>

<!-- tabs -->
<table border="0" cellpadding="0" cellspacing="0" height="20">
  <tr>
    <td height="20" onmouseover="this.style.background='#808080';" onmouseout="this.style.background='#E0DFE3';" 
      onclick="flipCell(1);this.style.background='#808080';" nowrap>
      Pagina NL
    </td>
    <td height="20" onmouseover="this.style.background='#808080';" onmouseout="this.style.background='#E0DFE3';" 
      onclick="flipCell(2);this.style.background='#808080';" nowrap>
      Pagina DE
    </td>
  </tr>
</table>

<!-- pagina's -->
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr style="display:block" id="taalnl">
    <td>
      DE gedeelte
    </td>
  </tr>
  <tr style="display:none" id="taalde"> 
    <td>
      DE gedeelte
    </td>
  </tr>
</table>

Dit werkt prima. Wat ik alleen niet voor elkaar krijg is dat de geselecteerde TAB de donkergrijze kleur aanhoud wanneer deze geselecteerd is (OnClick). De pagina wordt dus wel keurig gewisseld, alleen de tab zelf wordt weer lichtgrijs door het OnMouseout event. Ik heb al van alles geprobeerd, zelfs de HTML waarin de tabregels omschreven worden in een DIV laten vervangen door INNERHTML.

Ben een beginner op het gebied van Javascript, meestal lukt het me wel maar hier kom ik niet echt uit. Iemand een idee?

[ Voor 18% gewijzigd door klaaz op 12-01-2005 14:16 ]


  • Rhapsody
  • Registratie: Oktober 2002
  • Laatst online: 08:29

Rhapsody

In Metal We Trust

Ik zou met CSS classes gaan werken dan
Je kunt dan heel eenvoudig met javascript werken en dan de (CSS) className dynamisch veranderen.

zo dus:
JavaScript:
1
document.getElementById(id).className = "active";

[ Voor 20% gewijzigd door Rhapsody op 12-01-2005 14:19 ]

🇪🇺 pro Europa!


  • klaaz
  • Registratie: April 2000
  • Laatst online: 24-04 16:54

klaaz

it's me!

Topicstarter
Daar heb ik ook al aan gedacht:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
    <td id="nl" height="20" onmouseover="this.style.background='#808080';" onmouseout="this.style.background='#E0DFE3';" 
      onclick="flipCell(1);this.style.background='#808080';" nowrap>
      Pagina NL
    </td>
    <td id="de" height="20" onmouseover="this.style.background='#808080';" onmouseout="this.style.background='#E0DFE3';" 
      onclick="flipCell(2);this.style.background='#808080';" nowrap>
      Pagina DE
    </td>


<knip>

    <td height="20" onmouseover="this.style.background='#808080';" onmouseout="this.style.background='#E0DFE3';" 
      onclick="flipCell(1);document.getElementById(de).style.backgroundColor = '#E0DFE3';" nowrap>
      Pagina NL
    </td>
    <td height="20" onmouseover="this.style.background='#808080';" onmouseout="this.style.background='#E0DFE3';" 
      onclick="flipCell(2);document.getElementById(nl).style.backgroundColor = '#E0DFE3';" nowrap>
      Pagina DE
    </td>

Dit werkt niet... Dus ik doe iets fout denk ik :)

  • klaaz
  • Registratie: April 2000
  • Laatst online: 24-04 16:54

klaaz

it's me!

Topicstarter
mmmmm, ben eruit! Dank zij Rhapsody :)

code:
1
2
3
4
5
6
7
8
9
10
11
12
<style>
.active {
 background-color:#808080;
 }
.inactive {
 background-color:#E0DFE3;
 }
</style>
                    
<span id="nl" valign="middle" class="active" onclick="flipCell(1); this.className='active'; document.getElementById('de').className='inactive';">&nbsp;Pagina NL&nbsp;[img]"images/vlaggen/vlaggen_mini_nl.gif"></span>
                            
<span[/img]&nbsp;Pagina DE&nbsp;[img]"images/vlaggen/vlaggen_mini_de.gif"></span[/img]

  • Rhapsody
  • Registratie: Oktober 2002
  • Laatst online: 08:29

Rhapsody

In Metal We Trust

Scheelt ook heleboel code :)

🇪🇺 pro Europa!