Following up on this post, I am going further for a bit more challenge - how can I loop the div element which only has z-index only?
css,
#layer-1 { z-index:1; position:absolute; }
#layer-2 { z-index:2; position:absolute; }
#layer-3 { z-index:3; position:absolute; }
html,
<div id="layer-1">layer-1</div>
<div id="layer-2">layer-2</div>
<div id="layer-3">layer-3</div>
<div id="layer-4">layer-4</div>
jquery,
var index_highest = 0;
// more effective to have a class for the div you want to search and
// pass that to your selector
$("div").each(function() {
// always use a radix when using parseInt
var index_current = parseInt($(this).css("zIndex"), 10);
alert(index_current);
if(index_current > index_highest) {
index_highest = index_current;
}
});
The jquery code here is looping each of the div element. It will not be a good solution when I have tons of the divs on my root document. so I think, ideally the code could just loop the div element which has z-index only, then ignore the rest of the divs.
Is it possible?
Thanks.