Solved

How do I change the z-index by clicking anywhere other than on the element?

Posted on 2010-09-09
5
280 Views
Last Modified: 2013-11-19
Here's what I am doing... I have an child element that has a z-index of -1 to begin with.  Once the parent is clicked, it changes the z-index of the child to 9999 to give it the feel of a pop-up.  Now when I click anywhere else on the page besides the parent or the child, I want the z-index of the child to go back to -1.  Can anyone provide help with this?

Thanks,
TWB
0
Comment
Question by:TWB_Systems
5 Comments
 
LVL 6

Expert Comment

by:DalHorinek
Comment Utility
I'm not sure if this will work, just guessing.

$(body).click( function() {
       $("#popup").css({ "z-index": -1});
});
0
 

Author Comment

by:TWB_Systems
Comment Utility
I'm doing Javascript, not JQuery.
0
 
LVL 40

Expert Comment

by:gurvinder372
Comment Utility
<body onclick="changeZIndex()" >
</body>

function changeZIndex()
{
   document.getElementById("popup").style.zindex = -1;
}
0
 
LVL 3

Accepted Solution

by:
Marbleman earned 500 total points
Comment Utility

if you have mutiple popus it is quit easy to bring one in front by defining a global value for the currnet z-Index and increasing the one from the window like this:

var myGlobalZindex = 8000;

document.getElementById("popup").style.zindex = myGlobalZindex++;

You can do that whenever a div is clicked and it's z-Index is less than myGlobalZindex - 1

That leads to fact that you do not have to bring anything into back instead of bringing divs to front.
The reason is:

You cannot define a body.onclick like DalHorinek suggests. Because your body is probably not empty but filled with other elements. So you will click those instead of the body. And they do not pass the the click through to their parent  elements.

The only way to bring a popup-div to back is to add something like a window-caption to it that contains a button (like a minimize-button)
0
 

Author Closing Comment

by:TWB_Systems
Comment Utility
I just added a div with 100% width and 100% height that was one less than the current popup that way when I click that, I can send the new div to the back and the popup to hidden.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now