Solved

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

Posted on 2010-09-09
5
283 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
ID: 33641057
I'm not sure if this will work, just guessing.

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

Author Comment

by:TWB_Systems
ID: 33641242
I'm doing Javascript, not JQuery.
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33641268
<body onclick="changeZIndex()" >
</body>

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

Accepted Solution

by:
Marbleman earned 500 total points
ID: 33641589

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
ID: 33737155
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Best Way to remove the port from a URL? 15 32
where is team.js? 3 23
Can't get container centered 4 11
Else condition 9 15
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…

813 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

16 Experts available now in Live!

Get 1:1 Help Now