At risk of being told this is a duplicate question, I am trying to find out how to get the highest z-Index value of all the divs on a page INCLUDING those which have been created by jQuery.
The situation is, I have a toolTip div which sits at the top of the page and is populated onMouseover or onClick by jQuery based upon the trigger element.
I have a hidden div which onClick of a calling element shows up in a Lightbox style window which is given it's z-Index by jQuery. I need to be able to trigger my onMouseover toolTip from an element within this div, but it's currently showing behind it.
Clearly I could do it manually, but for future use I thought a computed method would be better...
Googling brought me to SO as usual, to this article How can you figure out the highest z-index in your document?
From which I found
function findHighestZIndex(elem) {
var elems = document.getElementsByTagName(elem);
var highest = 0;
for (var i = 0; i < elems.length; i++) {
var zindex = document.defaultView.getComputedStyle(elems[i], null).getPropertyValue("z-index");
if ((zindex > highest) && (zindex != 'auto')) {
highest = zindex;
}
}
return (highest * 1);
}
Which works fine for elements which have explicitly set z-Indexes by CSS.
However, not divs shown/populated by jQuery.
The function above ignores this modal window, presumably because the z-Index is programatically created?
I found this function also on SO
function getMaxZIndex() {
var zIndexMax = 0;
$('div').each(function () {
if ($(this).css('z-index') > zIndexMax) zIndexMax = $(this).css('z-index');
});
return (zIndexMax * 1);
}
But for some reason that returns 'NAN'
I think I need to use 'live' somewhere in here, but not sure how to go about doing it.
Once again, apologies if anyone thinks this is a duplicate question, but the questions I've found here don't quite answer this issue.