Find and Trump Z-Index on all Elements on a Page with jQuery

The jQuery snippet below will search all HTML elements on a page and find the element with the highest z-index value and capture that value in a variable – then using the .css function in jQuery, assign and increment that value by 1 to a selector you have chosen.

//add in our z-indexstuff
var index_highest = 0;
// Search all elements with '*'
$("*").each(function() {
var index_current = parseInt($(this).css("zIndex"), 10);
if (index_current > index_highest) {
index_highest = index_current;
//now the highest number is obtained and captured in the 'index_highest' variable - add 1 to it and assign to your element
//ref -
view raw z-index.js hosted with ❤ by GitHub

Leave a Comment