views:

458

answers:

2

Hi all, can anyone tell me how can i find zindex of a div in Google chrome document.getElementById(id).style.zIndex;//does not work

+2  A: 

Use jQuery.

$('#id').css( 'zIndex' )
Stefan Kendall
A: 

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.

David