Last active
April 26, 2019 17:17
-
-
Save MattyQ/54465699ccce526a24edea60ee50e9c7 to your computer and use it in GitHub Desktop.
Get highest z-index in a given target (Javascript)
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
/** | |
* @fileoverview Queries the computed styles for a given element to determine the highest z-index. | |
* For example, GET_Z_INDEX(document) returns the highest z-index in the DOM. | |
*/ | |
/** | |
* @function GET_Z_INDEX | |
* @param {object} parent_node The target parent node. The function returns the highest z-index of parent_node's children. | |
* @returns {number} | |
*/ | |
function GET_Z_INDEX(parent_node) { | |
var stored_z_index = 0; | |
parent_node.querySelectorAll("*").forEach(function(element) { | |
var z_index = parseInt(getComputedStyle(element).zIndex); | |
if (isNaN(z_index) === false && z_index > stored_z_index) { | |
stored_z_index = z_index; | |
} | |
}); | |
return stored_z_index; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment