0

Possible Duplicate:
How can you figure out the highest z-index in your document?

I need to implement an alert-type modal popup that appears with a dimmed background. The problem is, we may have other elements on the page being showed that are also modals with z-indexes above default.

How do I determine the appropriate z-index that makes a given element the highest-layered element?

(jQuery is fine.)

Community
  • 1
  • 1
CantSleepAgain
  • 3,743
  • 3
  • 21
  • 18
  • 1
    Have in mind that z-index have maximum value, so if you are not planning to display more modals after this you can just set it to the max, for more info check http://stackoverflow.com/questions/491052/mininum-and-maximum-value-of-z-index – Ilian Iliev Aug 25 '10 at 06:25

1 Answers1

0

Ideally, you should know, which elements you want to scan for z-index. Lets say if you are using some DIVs with "my-modal-class" CSS class as modal popup's then you can use something like this:

function getMaxZIndex()
{
   var allModalDialogs = $('DIV.my-modal-class');
   var zIndexMax = 0;
   allModalDialogs.each(function() {
     if ($(this).css('z-index') > zIndexMax) zIndexMax = $(this).css('z-index');
   });
   return zIndexMax;
}
dimarzionist
  • 18,517
  • 4
  • 22
  • 23