Skip to content
Advertisement

With JavaScript, can I change the Z index/layer of an SVG element?

Let’s say I have a couple composite shapes (<g>). I want to be able to click and drag them, but I want the one I happen to be dragging at the moment to be on TOP of the other one in the Z order, so that if I drag it over the OTHER one, the other one should be eclipsed.

Advertisement

Answer

Z index in SVG is defined by the order the elements appear in the document (subsequent elements are painted on top of previous elements).

You will have to change the element order if you want to bring a specific shape to the top.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement