How can I find the highest z-index within a document no matter what tags they are?
I found this code but I tested it and it does not work,
//include jQuery.js -- visit: http://jquery.com/
$(function(){
var maxZ = Math.max.apply(null,$.map($('body > *'), function(e,n){
if($(e).css('position')=='absolute')
return parseInt($(e).css('z-index'))||1 ;
})
);
alert(maxZ);
});
Any better approach to do this?
EDIT:
It seems to work if I change the code to this,
$('body *')
$('body > *') --> is for div only I guess.
This seems to work:
jsFiddle example
I think one of the issues with the code you posted is that you're only checking for absolutely positioned elements.
This isn't the most efficient solution, but it should work. jsFiddle.
Please note you have to have a position specified in order for the z-index to return a value.
Just to add a solution without jQuery: