Stacking vs linking of pages and common target ids

I am trying to have a “newResource” page that can call the same page (ie: stack) if needed.
It seems to work in my app except that when I modify it with Dom7("#id").html(…) , I believe that the underlying page is modified, rather than the stacked one. They share the same target id (and form ids), I suppose, but it would be hard to distinguish and I would have though it would reference the latest page? Is that possible, or do I need to get tricky with the ids.
I am trying to do it this way so that I can keep track of which resource is parent to which child, passing back id on save.

I have created a quick example here to illustrate what I am after:
https://jsfiddle.net/pworthing/va6Lezpf/84/

Basically, I have a main page that can call “newResource” to navigate to a page on top. Each time it does this, a counter would be incremented and the latest id is added to the top page. I say would be, because it seems to get a 404 error in my example (unlike my local app)??

One other problem with the example is that the “go back one level” button does not work. I added a back arrow instead but would love to know why this button does not work as a related question.

This will always select FIRST matching element. If you need last, try Dom7("#id").eq(-1) or better reference it correctly based on current page, e.g.:

 Dom7(".page-current #id")

thank you for this, it really helped. I also see now we can add data-name to pages.
I would have thought the current one would be accessed first but I looked at the dom now and I see how they get added sequentially and the current one is on the bottom. I will have to change my DOM calls as there may be multiple cases of duplicate variables. I also have javascript that gets added to each page which might cause issues. Maybe there is a way to add javascript to be confined in a page ?

Also curious, my recurring calls to add a reference now stop at around 4 and I am not sure why. Is there maybe a limit to the number of pages that can be added or do I have something else going on? Not sure if I need more but I would love to understand. Thanks again