Created
August 19, 2011 21:42
-
-
Save kaimallea/1158088 to your computer and use it in GitHub Desktop.
Return the highest z-Index used across all elements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Return the highest z-Index used across all elements | |
**/ | |
function getHighIndex (selector) { | |
// No granularity by default; look at everything | |
if (!selector) { selector = '*' }; | |
var elements = document.querySelectorAll(selector) || | |
oXmlDom.documentElement.selectNodes(selector), | |
i = 0, | |
e, s, | |
max = elements.length, | |
found = []; | |
for (; i < max; i += 1) { | |
e = window.getComputedStyle(elements[i], null).zIndex || elements[i].currentStyle.zIndex; | |
s = window.getComputedStyle(elements[i], null).position || elements[i].currentStyle.position; | |
// Statically positioned elements are not affected by zIndex | |
if (e && s !== "static") { | |
found.push(parseInt(e, 10)); | |
} | |
} | |
return found.length ? Math.max.apply(null, found) : 0; | |
} |
Totally missed this comment! I chose the former for clarity, but yes there is a cooler way. ;-)
Not sure why but it gives me NaN on Firefox's console.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could write:
more modernly as:
Not better. Not worse. Cooler.