on a website I want to have an element take up the entire space of the screen (after an event), but I can't seem to manage to get it in front of all the other elements on my website. Do I have to set positions and z-indexes for everything or is there another way of setting the element I want in front of everything else?
Asked
Active
Viewed 42 times
2 Answers
0
If you want this thing always on top, just set its z-index
to 999 (or something higher than you know everything else is).

rvighne
- 20,755
- 11
- 51
- 73

Brian McCall
- 1,831
- 1
- 18
- 33
0
Brute force.
function getMaxZ() {
var all = document.querySelectorAll('*');
var len = all.length;
var maxZ = 0;
var dv = document.defaultView;
for (var i = 0; i < len ; i++) {
var el = all[i];
var thisZ = el.currentStyle ? el.currentStyle : dv.getComputedStyle(el, null);
thisZ = thisZ.zIndex.replace(/[^\d]/,'') * 1;
if (thisZ > maxZ) maxZ = thisZ;
}
return maxZ;
}
alert(getMaxZ());

wolfhammer
- 2,641
- 1
- 12
- 11