How to find the highest z-index using jQuery

后端 未结 11 1167
终归单人心
终归单人心 2020-11-28 07:42

I have a number of div elements with different z-index. And I want to find the highest z-index among these divs - how can I achieve it?

CSS:

#layer-1         


        
11条回答
  •  盖世英雄少女心
    2020-11-28 08:28

    This would do it:

    $(document).ready(function() {
        var array = [];
        $("div").each(function() {
            array.push($(this).css("z-index"));
        });
        var index_highest = Math.max.apply(Math, array);
        alert(index_highest);
    });
    

    Try this

提交回复
热议问题