Skip to content

Instantly share code, notes, and snippets.

@jsatk
Last active December 31, 2015 02:29
Show Gist options
  • Save jsatk/7921133 to your computer and use it in GitHub Desktop.
Save jsatk/7921133 to your computer and use it in GitHub Desktop.
For when you really want your shit on top.
var fuckYouIWantMyShitOnTop = function (idOfElementYouWantOnTop) {
var all = document.getElementsByTagName("*"),
maxZIndex = 9007199254740992, // https://gist.github.com/jsatk/7921133#comment-968150
i, highestZIndex, currentZIndex, currentEl;
for (i = all.length - 1; i >= 0; i--) {
currentEl = all[i];
currentZIndex = Number(currentEl.style.zIndex);
if (isNaN(currentZIndex)) continue;
highestZIndex = isNaN(highestZIndex) || currentZIndex > highestZIndex ? currentZIndex : highestZIndex;
currentEl.style.zIndex = currentZIndex === maxZIndex ? currentZIndex - 1 : currentZIndex;
}
document.getElementById(idOfElementYouWantOnTop).style.zIndex = highestZIndex + 1;
};
@jsatk
Copy link
Author

jsatk commented Dec 12, 2013

@joelmccracken @msepcot Done :)

@chriscoyier that's brilliant and terrifying. This entire thing is terrifying and was created as a joke. The only real use case I can see for this is if you're on a giant project and some element keeps getting covered up by other non-careful coders who abuse z-index you could invoke this script with the ID if the el you want on top somewhere ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment