For starters you would have to add a position to those elements, otherwise they won't have a z-index, and would just return auto.
.selected {
z-index : 10;
position: relative;
}
Then you look at the element itself, and then it's parents, to see if any of them has a matching z-index, like so:
$("a").on('click', function(e){
e.preventDefault();
var Zidx = 10,
closest = null;
$(this).parents().addBack().each(function() {
if ( parseInt( $(this).css('z-index'), 10) === Zidx) {
closest = this;
return false;
}
});
if (closest) alert( $(closest).prop('tagName') );
});