Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to change z-index with event handler?

Status
Not open for further replies.

kippie

Technical User
Nov 8, 2001
158
In the HTML below there are 4 layers with each a z-index. I'm looking for a way to change these indexes so that I can choose with an event handler which layer is on top. But I have no clue how to do this. Can anyone help?

This is the HTML:
<html>
<head>
<meta http-equiv=&quot;content-type&quot; content=&quot;text/html;charset=iso-8859-1&quot;>
<style type=&quot;text/css&quot;><!--
#layer { position: absolute; top: 31px; left: 168px; width: 100px; height: 100px; z-index: 1; visibility: visible }
#layer2 { position: absolute; top: 90px; left: 234px; width: 100px; height: 165px; z-index: 2; visibility: visible }
#layer3 { position: absolute; top: 74px; left: 159px; width: 100px; height: 153px; z-index: 3; visibility: visible }
#layer4 { position: absolute; top: 45px; left: 215px; width: 112px; height: 106px; z-index: 4; visibility: visible }-->
</style>
</head>
<body>
<div id=&quot;layer&quot;>
This is layer 1<img height=&quot;74&quot; width=&quot;83&quot; src=&quot;<div id=&quot;layer2&quot;>
This is layer 2<img height=&quot;140&quot; width=&quot;100&quot; src=&quot;<div id=&quot;layer3&quot;>
This is layer 3<img height=&quot;102&quot; width=&quot;90&quot; src=&quot;<div id=&quot;layer4&quot;>
This is layer 4<img height=&quot;87&quot; width=&quot;112&quot; src=&quot;</body>
</html>

Kippie
 
i'm guessing you want to click the layers to bring them to the front:

<html>
<head>
<meta http-equiv=&quot;content-type&quot; content=&quot;text/html;charset=iso-8859-1&quot;>
<style type=&quot;text/css&quot;><!--
#layer { position: absolute; top: 31px; left: 168px; width: 100px; height: 100px; z-index: 1; visibility: visible }
#layer2 { position: absolute; top: 90px; left: 234px; width: 100px; height: 165px; z-index: 2; visibility: visible }
#layer3 { position: absolute; top: 74px; left: 159px; width: 100px; height: 153px; z-index: 3; visibility: visible }
#layer4 { position: absolute; top: 45px; left: 215px; width: 112px; height: 106px; z-index: 4; visibility: visible }-->
</style>

<script type=&quot;text/javascript&quot;>
function onTop(id) {
if (window.prevLayer) {
window.prevLayer.style.zIndex = 999;
}
var thisLayer = document.getElementById(id);
thisLayer.style.zIndex = 1000;
window.prevLayer = thisLayer;
}

</script>

</head>
<body>
<div id=&quot;layer&quot; onclick=&quot;onTop(this.id);&quot;>
This is layer 1<img height=&quot;74&quot; width=&quot;83&quot; src=&quot;<div id=&quot;layer2&quot; onclick=&quot;onTop(this.id);&quot;>
This is layer 2<img height=&quot;140&quot; width=&quot;100&quot; src=&quot;<div id=&quot;layer3&quot; onclick=&quot;onTop(this.id);&quot;>
This is layer 3<img height=&quot;102&quot; width=&quot;90&quot; src=&quot;<div id=&quot;layer4&quot; onclick=&quot;onTop(this.id);&quot;>
This is layer 4<img height=&quot;87&quot; width=&quot;112&quot; src=&quot;</body>
</html>


=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top