Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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