Salut à tous!

Je viens de pondre un (tout) petit script permettant de switcher entre 3 DIV, dont voici le code complet...


Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 
<html>
<head>
<style type="text/css">
#part{
display:block;
width:300px;
height:300px;
background-color:#CCCC33;
}
 
#corp{
display:none;
width:300px;
height:300px;
background-color:#0099FF;
}
 
#inst{
display:none;
width:300px;
height:300px;
background-color:#66CCFF;
}
 
</style>
<script type="text/javascript">
 
function switchPart() {
	if (
		document.getElementById("part").style.display == "block") {
	}
	else {
		document.getElementById("inst").style.display = "none";
		document.getElementById("corp").style.display = "none";
		document.getElementById("part").style.display = "block";
	}
}
 
function switchCorp() {
	if (
		document.getElementById("corp").style.display == "block") {
	}
	else {
		document.getElementById("inst").style.display = "none";
		document.getElementById("corp").style.display = "block";
		document.getElementById("part").style.display = "none";
	}
}
 
function switchInst() {
 
	if (
		document.getElementById("inst").style.display == "block") {
	}
	else {
		document.getElementById("inst").style.display = "block";
		document.getElementById("corp").style.display = "none";
		document.getElementById("part").style.display = "none";
	}
}
</script>
</head>
<body>
	<div id="onglets">
	  <div><a href="javascript:switchPart();"> Tarifs particuliers</a></div>
	  <div><a href="javascript:switchCorp();"> Tarifs Entreprises</a></div>
	  <div><a href="javascript:switchInst();"> Tarifs Education</a></div>
	</div>
	<div id="part"> DIV PARTICULIERS </div>
	<div id="corp"> DIV CORPORATE </div>
	<div id="inst"> DIV INSTITUTIONS </div>
</body>
</html>
Comment vous pouvez le voir, j'ai 3 function JavaScript, alors que j'effectue les mêmes actions sur les 3 DIV.

Alors je me demandais... Etant une grosse quiche en JavaScript (la preuve avec ce code simple en forme d'usine à gaz), il y aurait-t-il une bonne âme capable de m'expliquer (au pire) ou de m'optimiser (au mieux) ce petit code?

Merci d'avance, quelque soit la forme de votre contribution!