< BACK

Javascript tips, tricks and code snippets

Find the highest zIndex value

Based on this source - note the trick using forEach to iterate over a NodeList :

var max = 0
var els = document.querySelectorAll('*')
[].forEach.call(els, function(el){ 
  var zindex=document.defaultView.getComputedStyle(el,null).getPropertyValue("z-index");
  max = (parseInt(zindex)>max) ? zindex: max;
})
console.log(max)