Last active
January 24, 2020 05:12
-
-
Save windyakin/f2a6a550bf8192cdf4c1da8bd74a74bc to your computer and use it in GitHub Desktop.
Get elements array sorted by z-index
This file contains 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
// List | |
Array.prototype.map.call( | |
document.getElementsByTagName('*'), | |
(element) => { | |
return { | |
element: element, | |
zIndex: parseInt(getComputedStyle(element)["z-index"]) | |
} | |
} | |
).filter( | |
(item) => !isNaN(item.zIndex) | |
).sort( | |
(a, b) => b.zIndex - a.zIndex | |
) | |
// Max only | |
Array.prototype.map.call( | |
document.getElementsByTagName('*'), | |
(element) => { | |
return { | |
element: element, | |
zIndex: parseInt(getComputedStyle(element)["z-index"]) | |
} | |
} | |
).filter( | |
(item) => !isNaN(item.zIndex) | |
).reduce( | |
(accumulator, current) => { | |
return accumulator.zIndex > current.zIndex ? accumulator : current | |
}, | |
{ element: null, element: -1 } | |
) |
This file contains 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
Array.prototype.map.call(document.getElementsByTagName('*'), (element) => { return { element: element, zIndex: parseInt(getComputedStyle(element)["z-index"]) } }).filter((item) => !isNaN(item.zIndex)).reduce((accumulator, current) => { return accumulator.zIndex > current.zIndex ? accumulator : current }, { element: null, element: -1 }) |
This file contains 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
Array.prototype.map.call(document.getElementsByTagName('*'), (element) => { return { element: element, zIndex: parseInt(getComputedStyle(element)["z-index"]) } }).filter((item) => !isNaN(item.zIndex)).sort((a, b) => b.zIndex - a.zIndex) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment