• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

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

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
TWB_Systems
Asked:
TWB_Systems
1 Solution
 
DalHorinekCommented:
I'm not sure if this will work, just guessing.

$(body).click( function() {
       $("#popup").css({ "z-index": -1});
});
0
 
TWB_SystemsAuthor Commented:
I'm doing Javascript, not JQuery.
0
 
Gurvinder Pal SinghCommented:
<body onclick="changeZIndex()" >
</body>

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

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
 
TWB_SystemsAuthor Commented:
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

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now