Click to See Complete Forum and Search --> : zIndex scipt wont work


Kovo88
September 12th, 2007, 10:48 AM
Im trying to get this script to function like it should.
Basically I have two divs that overlap each other. I want it so that everytime one of the divs is clicked on, it comes to the front (so on top of the other one). This can happen anywhere from once to 2000 times (exaggeration).

<script>
function contentMouseDown() {

var topZ = 5;
var dragContent = document.getElementById('windowone');
var dragContent2 = document.getElementById('windowtwo');
if ( ! dragContent.id.match("windowone")) {
dragContent = findParentTagById(dragContent, "windowone");
}
if (dragContent) {
dragContent.style.zIndex = topZ;
dragContent.titlediv.style.zIndex = topZ;
topZ++;
}
if ( ! dragContent2.id.match("windowtwo")) {
dragContent2 = findParentTagById(dragContent2, "windowtwo");
}
if (dragContent2) {
dragContent2.style.zIndex = topZ;
dragContent2.titlediv2.style.zIndex = topZ;
topZ++;
}
}



</script>

For somereason it just does not work. I need a script that increases the zindex by 1 or 5 or wtv every time a div is clicked.

PeejAvery
September 12th, 2007, 11:11 AM
The reason it doesn't work is because you redeclare the zIndex to 5 every time the function fires.
var topZ = 5;

Note: you need the type attribute in the <script> tag.
<script type="text/javascript">
var topZ = 5;
function contentMouseDown() {
var dragContent = document.getElementById('windowone');
var dragContent2 = document.getElementById('windowtwo');
if ( ! dragContent.id.match("windowone")) {
dragContent = findParentTagById(dragContent, "windowone");
}
if (dragContent) {
dragContent.style.zIndex = topZ;
dragContent.titlediv.style.zIndex = topZ;
topZ++;
}
if ( ! dragContent2.id.match("windowtwo")) {
dragContent2 = findParentTagById(dragContent2, "windowtwo");
}
if (dragContent2) {
dragContent2.style.zIndex = topZ;
dragContent2.titlediv2.style.zIndex = topZ;
topZ++;
}
}
</script>

Kovo88
September 12th, 2007, 11:28 AM
Hmm thanks, but now the issue is ht once I select windowone and it becomes over windowtwo, window two never actually comes back over window one if i click on it. Once Window one becomes first over window two, I cant get window two to be over w1 again.... ha

<div id="windowone" onmousedown="contentMouseDown();"> bah </div>

<div id="windowtwo" onmousedown="contentMouseDown();"> blah </div>

Kovo88
September 12th, 2007, 11:44 AM
4get it, firgure dit out, thanks

PeejAvery
September 12th, 2007, 11:50 AM
You're welcome. Good luck with the rest! :wave: