-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActiveThis.html
More file actions
59 lines (55 loc) · 1.69 KB
/
ActiveThis.html
File metadata and controls
59 lines (55 loc) · 1.69 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Using Active & This</title>
<style>
#div1 .active {background: rgb(229, 154, 248);}
#div1 div {width:200px; height:200px;
background:goldenrod;
border:5px solid lightgray; display:none;}
</style>
<script>
window.onload=function()
{
var oDiv=document.getElementById('div1');
var aBtn=oDiv.getElementsByTagName('input');
var aDiv=oDiv.getElementsByTagName('div');
for(var i=0;i<aBtn.length;i++)
{
aBtn[i].index=i;
aBtn[i].onclick=function ()
{
for(var i=0;i<aBtn.length;i++)
{
aBtn[i].className='';
aDiv[i].style.display='none';
}
//alert(this.value);
//alert(this.index)
this.className='active';
aDiv[this.index].style.display='block';
};
}
};
</script>
</head>
<body>
<div id="div1">
<input class="active" type="button" value="Magnus" />
<input type="button" value="Bella" />
<input type="button" value="Edwin" />
<input type="button" value="Jag" />
<div style="display:block;">Pappa</div>
<div>MinFlicka</div>
<div>MinPojke</div>
<div>Mamma</div>
</div>
</body>
</html>
<!-- <input class="active" type="button" value="Madnus" index="0" /> -->
<!--OBS! 'index' är inte standard funktion i html därför kan inte visas i
standard browser via html. -->
<!-- Men det kan visas bra om det kodas i JS istället
se ovan:aBtn[i].index=i;
sedan:aDiv[this.index].style.display='block';-->