This gives me auto: I need the number, so I can move one 开发者_StackOverflow中文版above the other?
// Swop div index
$("#panel div").each(function(){
alert($(this).css('z-index'));
});
I don't think that browsers handle the z-index
the way you seem to be expecting them to. For elements without a z-index
, there just isn't a value there (which is basically what "auto" means).
Elements with a z-index of auto are laid out in the order they appear in the document tree.
If you want one on top, make its z-index equal to the childNodes length of the parent. (or one more than the largest z-index of any of the child nodes, if there are any set).
Be sure to set the z-index as a string and not an integer, and parseInt to compare any existing z-indexes.
try this
window.getZIndex = function (e) {
var z = window.document.defaultView.getComputedStyle(e).getPropertyValue('z-index');
if (isNaN(z)) return window.getZIndex(e.parentNode);
return z;
};
usage
var myZIndex = window.getZIndex($('#myelementid')[0]);
(if parent gets to root it will return 0)
精彩评论