As others here have said, z-index is defined by the order the element appears in the DOM. If manually reordering your html isn't an option or would be difficult, you can use D3 to reorder SVG groups/objects.
Updating SVG Element Z-Index With D3
At the most basic level (and if you aren't using IDs for anything else), you can use element IDs as a stand-in for z-index and reorder with those. Beyond that you can pretty much let your imagination run wild.
Examples in code snippet
var circles = d3.selectAll('circle')_x000D_
var label = d3.select('svg').append('text')_x000D_
.attr('transform', 'translate(' + [5,100] + ')')_x000D_
_x000D_
var zOrders = {_x000D_
IDs: circles[0].map(function(cv){ return cv.id; }),_x000D_
xPos: circles[0].map(function(cv){ return cv.cx.baseVal.value; }),_x000D_
yPos: circles[0].map(function(cv){ return cv.cy.baseVal.value; }),_x000D_
radii: circles[0].map(function(cv){ return cv.r.baseVal.value; }),_x000D_
customOrder: [3, 4, 1, 2, 5]_x000D_
}_x000D_
_x000D_
var setOrderBy = 'IDs';_x000D_
var setOrder = d3.descending;_x000D_
_x000D_
label.text(setOrderBy);_x000D_
circles.data(zOrders[setOrderBy])_x000D_
circles.sort(setOrder);
_x000D_
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>_x000D_
_x000D_
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 100"> _x000D_
<circle id="1" fill="green" cx="50" cy="40" r="20"/> _x000D_
<circle id="2" fill="orange" cx="60" cy="50" r="18"/>_x000D_
<circle id="3" fill="red" cx="40" cy="55" r="10"/> _x000D_
<circle id="4" fill="blue" cx="70" cy="20" r="30"/> _x000D_
<circle id="5" fill="pink" cx="35" cy="20" r="15"/> _x000D_
</svg>
_x000D_
The basic idea is:
Use D3 to select the SVG DOM elements.
var circles = d3.selectAll('circle')
Create some array of z-indices with a 1:1 relationship with your SVG elements (that you want to reorder). Z-index arrays used in the examples below are IDs, x & y position, radii, etc....
var zOrders = {
IDs: circles[0].map(function(cv){ return cv.id; }),
xPos: circles[0].map(function(cv){ return cv.cx.baseVal.value; }),
yPos: circles[0].map(function(cv){ return cv.cy.baseVal.value; }),
radii: circles[0].map(function(cv){ return cv.r.baseVal.value; }),
customOrder: [3, 4, 1, 2, 5]
}
Then, use D3 to bind your z-indices to that selection.
circles.data(zOrders[setOrderBy]);
Lastly, call D3.sort to reorder the elements in the DOM based on the data.
circles.sort(setOrder);
[3,4,1,2,5]
moves/reorders the 3rd circle (in the original HTML order) to be 1st in the DOM, 4th to be 2nd, 1st to be 3rd, and so on...