JSFiddle - React, Tailwind, and code Playground
HTML
<img class="click-to-top" style="top:10px;left:10px">1</div>
<img class="click-to-top" style="top:20px;left:90px">2</div>
<img class="click-to-top" style="top:60px;left:70px">3</div>
<img class="click-to-top" style="top:90px;left:30px">4</div>
CSS
div.click-to-top {
position: absolute;
background-color: rgba(255, 200, 200, 0.7);
border: black solid 1px;
width: 100px;
height: 100px;
}
JavaScript
// Answer for http://stackoverflow.com/a/13112731/592125
$('img').click(function(){
var topZ = 0;
$('img').each(function(){
var thisZ = parseInt($(this).css('z-index'), 10);
if (thisZ > topZ){
topZ = thisZ;
}
});
$(this).css('z-index', topZ+1);
});