Skip to content

Instantly share code, notes, and snippets.

@matt-diehl
Created June 1, 2017 16:19
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 matt-diehl/dd00524aa0b7e79372faa407bf8f383c to your computer and use it in GitHub Desktop.
Save matt-diehl/dd00524aa0b7e79372faa407bf8f383c to your computer and use it in GitHub Desktop.
Find all elements on a page with a specified z-index and log them to the console, sorted high to low
'use strict';
(function() {
var allElements = document.querySelectorAll('*');
var zIndexElements = [].map.call(allElements, function(el) {
var style = window.getComputedStyle(el, null);
var zIndex = style.getPropertyValue('z-index');
return {
el: el,
zIndex: zIndex && zIndex !== 'auto' ? parseInt(zIndex) : undefined
}
})
.filter(el => el.zIndex)
.sort((a, b) => {
return b.zIndex - a.zIndex;
});
console.table(zIndexElements);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment