Get the highest z-index in a page using javascript

Use the following javascript function to get the biggest ZIndex in a page if you need to add an element above all others.

<script>
function zin(){
var allElements = document.getElementsByTagName('*'); 
var vaval=0
var vaz=0
for (var i = 0; i< allElements.length; i++){
if(navigator.appName.substring(0,5)=="Micro" && allElements[i].parentNode==document.documentElement.childNodes[1]){
vaz=allElements[i].currentStyle='zIndex'
}
if(navigator.appName.substring(0,5)!="Micro" && allElements[i].parentNode==document.documentElement.childNodes[1]){
vaz=getComputedStyle(allElements[i],null).getPropertyValue('z-index');
}
if(vaz>vaval){
vaval=vaz
}
}
alert(vaval)
}
</script>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.