We have already 2019 and z-index
is still not supported in SVG.
You can see on the site SVG2 support in Mozilla that the state for z-index
– Not implemented.
You can also see on the site Bug 360148 "Support the 'z-index' property on SVG elements" (Reported: 12 years ago).
But you have 3 possibilities in SVG to set it:
element.appendChild(aChild);
parentNode.insertBefore(newNode, referenceNode);
targetElement.insertAdjacentElement(positionStr, newElement);
(No support in IE for SVG)With all this 3 functions.
var state = 0,_x000D_
index = 100;_x000D_
_x000D_
document.onclick = function(e)_x000D_
{_x000D_
if(e.target.getAttribute('class') == 'clickable')_x000D_
{_x000D_
var parent = e.target.parentNode;_x000D_
_x000D_
if(state == 0)_x000D_
parent.appendChild(e.target);_x000D_
else if(state == 1)_x000D_
parent.insertBefore(e.target, null); //null - adds it on the end_x000D_
else if(state == 2)_x000D_
parent.insertAdjacentElement('beforeend', e.target);_x000D_
else_x000D_
e.target.style.zIndex = index++;_x000D_
}_x000D_
};_x000D_
_x000D_
if(!document.querySelector('svg').insertAdjacentElement)_x000D_
{_x000D_
var label = document.querySelectorAll('label')[2];_x000D_
label.setAttribute('disabled','disabled');_x000D_
label.style.color = '#aaa';_x000D_
label.style.background = '#eee';_x000D_
label.style.cursor = 'not-allowed';_x000D_
label.title = 'This function is not supported in SVG for your browser.';_x000D_
}
_x000D_
label{background:#cef;padding:5px;cursor:pointer}_x000D_
.clickable{cursor:pointer}
_x000D_
With: _x000D_
<label><input type="radio" name="check" onclick="state=0" checked/>appendChild()</label>_x000D_
<label><input type="radio" name="check" onclick="state=1"/>insertBefore()</label><br><br>_x000D_
<label><input type="radio" name="check" onclick="state=2"/>insertAdjacentElement()</label>_x000D_
<label><input type="radio" name="check" onclick="state=3"/>Try it with z-index</label>_x000D_
<br>_x000D_
<svg width="150" height="150" viewBox="0 0 150 150">_x000D_
<g stroke="none">_x000D_
<rect id="i1" class="clickable" x="10" y="10" width="50" height="50" fill="#80f"/>_x000D_
<rect id="i2" class="clickable" x="40" y="40" width="50" height="50" fill="#8f0"/>_x000D_
<rect id="i3" class="clickable" x="70" y="70" width="50" height="50" fill="#08f"/>_x000D_
</g>_x000D_
</svg>
_x000D_