title: How to calculate the effective z-index of an HTML element
body: <p>I would like to determine the z-index of an element on an html page from code.  I am using jQuery.</p>
  
  <p>jQuery will allow me to check the applied z-index using $(element).css("z-index").  If the z-index is not set on that element directly though, Firefox returns "auto" and IE returns "0".  The effective z-index of that node then depends on the z-index of its container.</p>
  
  <p>I figured I could calculate the effective z-index then by looking at the node and its parents until a z-index value is found.  The problem is, at least on IE, I cannot disambiguate an element with a z-index of 0 from an element who will inherit the z-index of its parent, as in both cases .css("z-index") returns 0.  Any thoughts on how to calculate the actual z-index of an element?</p>
  
  <p>If you want to experiment, you can use this code.  On IE it will output "0", "0", "0", "300".  On Firefox it will output "auto", "auto", "0", "300".</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
  &lt;script type="text/javascript"&gt;
      alert($("&lt;div&gt;&lt;/div&gt;").css("z-index"));
      alert($("&lt;div style='position:relative'&gt;&lt;/div&gt;").css("z-index"));
      alert($("&lt;div style='z-index:0'&gt;&lt;/div&gt;").css("z-index"));
      alert($("&lt;div style='z-index:100'&gt;&lt;/div&gt;").css("z-index"));
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>