At the moment, all of your individual SVGs overlap with each other, and any click that skips the triangle will be swallowed by the parent <svg> element.
The cleanest solution is to put all your polygons in one big SVG. However, there is another way to solve the problem using the pointer-events property.
Set pointer-events="none" to the <svg> elements so that clicks pass through them. But you will also need to set explicit pointer-events="fill" on your polygons, because otherwise they will inherit "none" from their parent SVGs.
var output = document.getElementById("output"); document.getElementById("red").addEventListener("click", function(e) { output.textContent = "red"; }); document.getElementById("green").addEventListener("click", function(e) { output.textContent = "green"; });
svg { position: absolute; top: 0; left: 0; pointer-events: none; } polygon { pointer-events: fill; } #output { margin-top: 120px; }
<svg width="100px" height="100px"> <polygon points="0,0,100,0,100,100" fill="red" id="red"/> </svg> <svg width="100px" height="100px"> <polygon points="0,0,100,100,0,100" fill="green" id="green"/> </svg> <div id="output"></div>
source share