I am trying to make my SVGs look like a "pie shape" which appears to be all fine, besides, i want each of them to have a different click event.
function one() {
alert("1");
}
function two() {
alert("2");
}
function three() {
alert("3");
}
function four() {
alert("4");
}
<svg style="position: absolute;height:auto;width:auto;" onClick="one()">
<path d="m 25.857864,25.857865 a 20,20 0 0 1 28.284271,-1e-6 L 40,40 Z"/>
</svg>
<svg style="position: absolute;height:auto;width:auto;" onClick="two()">
<path
d="m 25.857864,-54.142135 a 20,20 0 0 1 28.284271,-10e-7 L 40,-40 Z"
transform="rotate(90)" />
</svg>
<svg style="position: absolute;height:auto;width:auto;" onClick="three()">
<path
d="m -54.142136,-54.142135 a 20,20 0 0 1 28.284271,-10e-7 L -40,-40 Z"
transform="scale(-1)" />
</svg>
<svg style="position: absolute;height:auto;width:auto;" onClick="four()">
<path
d="m 25.857864,25.857865 a 20,20 0 0 1 28.284271,-1e-6 L 40,40 Z"
transform="matrix(0,1,1,0,0,0)"/>
</svg>
However my problem is, whenever i try, the last SVG in the code seems to be covering other SVGs in the code, such that only the last function {four() in the example} would be called out no matter which part of the circle i click on
One svg tag and assign onClick function to path tag like this and it works fine:
function one() {
alert("1");
}
function two() {
alert("2");
}
function three() {
alert("3");
}
function four() {
alert("4");
}
<svg style="position: absolute;height:auto;width:auto;">
<path d="m 25.857864,25.857865 a 20,20 0 0 1 28.284271,-1e-6 L 40,40 Z" onClick="one()"/>
<path
d="m 25.857864,-54.142135 a 20,20 0 0 1 28.284271,-10e-7 L 40,-40 Z"
transform="rotate(90)" onClick="two()"/>
<path
d="m -54.142136,-54.142135 a 20,20 0 0 1 28.284271,-10e-7 L -40,-40 Z"
transform="scale(-1)" onClick="three()" />
<path
d="m 25.857864,25.857865 a 20,20 0 0 1 28.284271,-1e-6 L 40,40 Z"
transform="matrix(0,1,1,0,0,0)" onClick="four()"/>
</svg>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With