Solved

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

Posted on 2010-09-09
5
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

710 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