View Full Version : Change z-index?

02-26-2003, 08:41 AM
Ok! this is p\my problem I have a drag and drop script like this:

<script language="JavaScript">
<!-- Hide
N = (document.all) ? 0 : 1;
var ob;
function MD(e) {
if (N) {
ob = document.layers[e.target.name];
return false;
else {
ob = event.srcElement.parentElement.style;
function MM(e) {
if (ob) {
if (N) {
ob.moveTo((e.pageX-X), (e.pageY-Y));
else {
ob.pixelLeft = event.clientX-X + document.body.scrollLeft;
ob.pixelTop = event.clientY-Y + document.body.scrollTop;
return false;
function MU() {
ob = null;

if (N) {
document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
document.onmousedown = MD;
document.onmousemove = MM;
document.onmouseup = MU;
// End -->

<div id="a" style="position:absolute;left:50;top:50; z-index:4;">
<img src="unu.gif" name="s">
<div id="b" style="position:absolute;left:50;top:100; z-index:3;">
<img src="doi.gif" name="d">
<div id="c" style="position:absolute;left:100;top:50; z-index:2;">
<img src="trei.gif" name="c">
<div id="d" style="position:absolute;left:100;top:100; z-index:1;">
<img src="patru.gif" name="h">

I want to chage z-index . In MD function I must place a command who change z-index of the curent div from let say z-index: 2 to z-index:4. :rolleyes:
How can I do this?

02-26-2003, 09:47 AM
objectRef.style.zIndex = 1;

just a hint on accessing css properties in javascript:

the corresponding property (when accessed by javascript) for every 2-word attribute in CSS which is separated by hyphen (-), is the first word then the second word where the first letter is capitalized.

z-index -> zIndex
font-size -> fontSize

02-26-2003, 10:52 AM
Thanks man!!! It was simple In MM function ob.zIndex = 1 and in MU function ob.zIndex=-1 and it works. :) Now the selectid pcture is always on top of the other. :thumbsup: