Skip to content

Instantly share code, notes, and snippets.

@cviebrock
Created April 9, 2021 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cviebrock/4e6be47816a34534f43ede3b13ecb53a to your computer and use it in GitHub Desktop.
Save cviebrock/4e6be47816a34534f43ede3b13ecb53a to your computer and use it in GitHub Desktop.
Get max z-index of all elements on a page
const reducer = (max, elem) => {
const s = window.getComputedStyle(elem);
const z = parseInt(s.getPropertyValue('z-index'), 10) || 0;
return Math.max(max, z);
};
const maxZ = Array.from(document.getElementsByTagName('*'))
.reduce(reducer, Number.MIN_SAFE_INTEGER);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment