Solved

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

Posted on 2010-09-09
5
286 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to count occurrences of each item in an array.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

617 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