I can get the id of an SVG object through getElementById
using only one.
But since I have 3 objects, how can I know the id of each one.
var shape = document.getElementById('rect1');
shape.onclick = function(){
alert(this.id);
};
<svg width=90% height=500px>
<rect id="rect1" ry=0 rx=0 x=50 y=50 width=20px height=20px fill=red />
<rect id="rect2" ry=0 rx=0 x=80 y=50 width=20px height=20px fill=blue />
<rect id="rect3" ry=0 rx=0 x=110 y=50 width=20px height=20px fill=green />
</svg>
Fiddle: link