What is default z-Index of
element in HTML, and how to get it using JavaScript?

前端 未结 6 2018
面向向阳花
面向向阳花 2021-02-01 15:13

So normally we can get z-Index value of a div element using, e.g:

var zindex = document.getElementById(\'id\').style.zIndex;

I am using this

6条回答
  •  [愿得一人]
    2021-02-01 16:11

    You might try window.getComputedStyle() on the element:

    https://developer.mozilla.org/en/DOM/window.getComputedStyle

    var e = document.getElementById('mydiv');
    var value = window.getComputedStyle(e[0], null)['zIndex']
    

    I got these values: "auto", "10". After changing: z-index: 10, position: relative.

提交回复
热议问题