This is a simple example of stacking text elements.
html:
<html>
<head>
<title>Program 2</title>
<link rel="stylesheet" type="text/css" href="ex2.css">
<script type="text/javascript" src="ex2.js"></script>
</head>
<body>
<p class="box" id="para1" onmouseover="display('para1');">
This is a paragraph.
</p>
<p class="box" id="para2" onmouseover="display('para2');">
This is a paragraph.
</p>
<p class="box" id="para3" onmouseover="display('para3');">
This is a paragraph.
</p>
</body>
</html>
css:
.box {
border: 1px solid black;
width: 500px;
position: absolute;
}
#para1 {
font-size: 20pt;
color: white;
background: red;
top: 150px;
left: 150px;
}
#para2 {
font-size: 20pt;
color: white;
background: blue;
top: 200px;
left: 200px;
}
#para3 {
font-size: 20pt;
color: white;
background: green;
top: 250px;
left: 250px;
}
js:
var defaultTop = 'para3';
function display(select)
{
newTop = document.getElementById(select)
oldTop = document.getElementById(defaultTop);
oldTop.style.zIndex = "0";
newTop.style.zIndex = "10";
defaultTop = select;
}
When I place var defaultTop = 'para3';
inside a function, only the para2
and para3
are displayed respectively as I move the mouse over, but not para1
. But when I place var defaultTop = 'para3';
outside the function all the para are displayed respectively. Why?