Posted By

adnan on 05/21/09


Tagged

javascript jquery


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

adnan
satie83


A better process to find maximum z-index within a page


 / Published in: jQuery
 

URL: http://abcoder.com/javascript/a-better-process-to-find-maximum-z-index-within-a-page/

I made an absolute tinny code to find the highest z-index of absolute DIV to show my shouting box and to make it appear absolutely at the top of all html elements.

I used selector of ”body > *‘ instead of ‘body *‘.

”body > *‘ means all tags/elements which are found at first depth of whether ”body *‘ selects all tags/elements at any depth. It doesn’t matter what’s is the maximum/highest z-index of an absolute element rather it matters what’s the maximum/highest z-index of the absolute elements which are next to in first depth only to show the shouting box on top most strata.

N.B. Shouting box is appended to document.body in this case.

  1. //include jQuery.js -- visit: http://jquery.com/
  2. $(function(){
  3. var maxZ = Math.max.apply(null,$.map($('body > *'), function(e,n){
  4. if($(e).css('position')=='absolute')
  5. return parseInt($(e).css('z-index'))||1 ;
  6. })
  7. );
  8. alert(maxZ);
  9. });

Report this snippet  

You need to login to post a comment.