I am trying to get the z-index property of some div using the following code.
$("#elementID").css("z-index")
But i am getting
"auto"
as result.
is it possible to get the Numeric values like 1,2,3.. in this case instead of auto .
please share the link, if this question has already answered in Stackoverflow.
jQuery UI:
To get the numeric value of the z-index property of your div regardless if it was set directly on it or inherited use:
$("elementID").zIndex();
Notice: zIndex
was removed in jQuery UI 1.10.
This method will start at the specified element and move on to its parents until it finds an element that has a z-index set. If it doesn't find anything, it will return 0.
JavaScript:
window.getZIndex = function (e) {
var z = document.defaultView.getComputedStyle(e).getPropertyValue('z-index');
if (isNaN(z)) return getZIndex(e.parentNode);
else return z;
};
Use it like so:
var z_Index = getZIndex($('#elementID')[0]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With