Div blocks are generated (pop-up) with the same z-index with js. How to assign different z-index?

Hello!
There was a following situation:
Clicking the button opens a pop-up window, there are the images by clicking on them, opens another popup slideshow that is in the same pop-up another pop-up. The problem is that both pop-up Windows have the same z-index. And that window, which in theory would have to be at the top (slideshow images), it appears under the previous one. On the website z-index for all pop-up Windows is generated using js and the same for everyone - 100002.
How to do that would be for each window z-index was different. Thanks in advance.
The js code from a file I attach
https://jsfiddle.net/sbfLt5ga/1/
July 12th 19 at 16:55
3 answers
July 12th 19 at 16:57
We need to implement the stack of popups. When you open the popup is added to the stack and is assigned a z-index on the basis of the position in the stack.
July 12th 19 at 16:59
There not what is not clear, the code is already compiled and compressed. Want the original not compressed.
July 12th 19 at 17:01
Friends, thanks for the replies.
I js in full 0, this will not be able to convert a stack of popups, or anything else.
I'm interested in, as in the line from the above js file (here it is: https://jsfiddle.net/sbfLt5ga/1/ ):
.css({position:"absolute",top:0,left:0,zIndex:100002})

in place zIndex implement some function type, zIndex:zIndex+1, such that each new program had its own z-index.
Or you may want each popup to somehow assign an id or class (ATU now there's just a div without anything)
And thank you again.
Made so that each popup is assigned to the id, but he is also the same for all.
Is it possible to make it so that-be were searching for a specific item id and it should be assigned a z-index, then - once again search for the item with the same id, and he would have assigned z-index+1, etc. - Sven commented on July 12th 19 at 17:04

Find more questions by tags JavaScript