Skip to content

Instantly share code, notes, and snippets.

@windyakin
Last active January 24, 2020 05:12
Show Gist options
  • Save windyakin/f2a6a550bf8192cdf4c1da8bd74a74bc to your computer and use it in GitHub Desktop.
Save windyakin/f2a6a550bf8192cdf4c1da8bd74a74bc to your computer and use it in GitHub Desktop.
Get elements array sorted by z-index
// 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 }
)
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 })
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