Geting z-index With DOM style.zIndex

I was not able to get the z-index of my page element using document.getElementById(“id”).style.zIndex. Please see my code in codepen https://codepen.io/CSSAnomaly/pen/YEQXjw

Hi,

AFAIK, the element.style property only gives you access to CSS properties defined inline. You should get the element’s computed style, like so:

var el = document.getElementById('block' + randIndex)
var style = window.getComputedStyle(el)
var zI = style.zIndex;

Then things will work as expected.

i m also looking for solution for same code so thank u so much becoz i found my solution. Thanks again

Post edited by TechnoBear to remove fake signature

Thank you so much, that is the solution I am looking for.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.