I recommend removing all z-indexes from your css. Then create a class called ".veryHighZ-Index", for example, and add this class to the clicked image and remove the class from the previously clicked image ...
I modified your code a bit, but this code should work here.
<html> <head> <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script> $(document).ready(function () { </script> <style type="text/css"> #pictures { width: 650px; height: 300px; margin-left: auto; margin-right: auto; margin-top: 20px; margin-bottom: 50px; background: lime; position: relative; overflow: hidden; } #top { top: 0; left: 0; position: absolute; } #center { top: 60px; left: 200px; position: absolute; } #bottom { top: 150px; left: 400px; position: absolute; } .top, .center, .bottom { width: 300px; height: 300px; border: 2px solid red; } .top {background: red;} .center {background: yellow;} .bottom {background: blue;} .veryhighz-index { z-index: 999999; } </style> </head> <body> <div id="pictures"> <div id="top" class="top"></div> <div id="center" class="center"></div> <div id="bottom" class="bottom"></div> </div> </body> </html>
In short, add the following code to your css
.veryhighz-index { z-index: 999999; }
and this code for javascript functions
//
source share