As long as there is no z-index for SVG, I made my rectangles change z-position with DOM manipulations. However, I have a new problem. For some reason transition stops to work. I suspect it is because of DOM reordering, but I HAVE TO use it like that.
function redZ() {
document.getElementById('svgField').appendChild(document.getElementById('redRect'));
document.getElementById('redRect').style.transition = "2s linear";
document.getElementById('redRect').style.fill = "black";
}
function blueZ() {
document.getElementById('svgField').appendChild(document.getElementById('blueRect'));
document.getElementById('blueRect').style.transition = "2s linear";
document.getElementById('blueRect').style.fill = "yellow";
}
<svg width="180" height="150" id="svgField">
<rect onclick="redZ()" id="redRect" x="0" y="0" width="100" height="100" fill="red" />
<rect onclick="blueZ()" id="blueRect" x="60" y="40" width="100" height="100" fill="blue" />
</svg>