Forum Moderators: open

Message Too Old, No Replies

changing elements of an existing class

         

walker

4:09 pm on Apr 27, 2005 (gmt 0)

10+ Year Member



Hi

Does anyone know if it is possible to change elements of a class such as the z-index number via an onclick command.

Basically I have a drag script with multiple objects, the idea is that when someone clicks on and drags an item it should be on the top most layer.

As it stands I have a system whereby I am simply switching the className back and forth each. One with a zindex of 2 and one with a zindex of 1.

Only problem is that when you have more than 2 elements to drag each requiring the top position when selected (WITHOUT modifying the order of the others) it becomes a little more complex.

Basically it would be ideal if there was some way of editing the class zindex to always be highest by perhaps looking for the highest zindex and adding 1 or something.....

Kind regards

Walker

Bernard Marx

8:26 pm on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have a global that starts off with any integer higher than the number of drag elements:

var topZIndex = 20;

Then assign an increneted value every time within the onclick part of the drag script:

elmRef.style.zIndex = topZIndex++;

This will be OK until Javascript runs out of precise integers.
(The World would have ended some millennia beforehand)

walker

7:12 pm on Apr 28, 2005 (gmt 0)

10+ Year Member



WOW!

THANK YOU -- THANK YOU -- THANK YOU!

I have been trying so many similar variations that didn't quite work or had flaws, much apprecieted!

Walker