can anyone tell me how can i find zindex of a div in Google chrome?
document.getElementById(id).style.zIndex; //does not work
can anyone tell me how can i find zindex of a div in Google chrome?
document.getElementById(id).style.zIndex; //does not work
Since z index is mentioned in the CSS part you won't be able to get it directly through the code that you have mentioned. You can use the following example.
function getStyle(el,styleProp)
{
var x = document.getElementById(el);
if (window.getComputedStyle)
{
var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
}
else if (x.currentStyle)
{
var y = x.currentStyle[styleProp];
}
return y;
}
pass your element id and style attribute to get to the function.
Eg:
var zInd = getStyle ( "normaldiv1" , "zIndex" );
alert ( zInd );
For firefox you have to pass z-index instead of zIndex
var zInd = getStyle ( "normaldiv1" , "z-index" );
alert ( zInd );
That is a standard cross-browser notation that works in my version of Chrome. I would check to make sure each part of your JavaScript returns what you expect before continuing:
alert(document.getElementById(id)); // should return an [object HTMLElement]
alert(document.getElementById(id).style); // should return an [object CSSStyleDeclaration]
alert(document.getElementById(id).style.zIndex); // should return blank (default) or a number
also, how do you know it's set? It could be inherit or auto... (which means it's not explicitly declared for that element).
Also, make sure you run it after the element is available in the DOM.