Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Numeric value of Z-index

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.

like image 308
Venkat Avatar asked Dec 24 '22 05:12

Venkat


1 Answers

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]);
like image 193
Angel Politis Avatar answered Jan 09 '23 00:01

Angel Politis