I have an SVG with a rect child element. The rect child has an onclick
event that gets another element by its ID and changes its background color. This works in Chrome on my desktop as well as the iOS emulators in the Chrome inspector. However, it doesn't trigger the event on iOS devices.
What can I change in my code to work on both desktop and iOS devices? Should I be listening for an additional event?
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" style="height: 200px; width: 200px; border: 4px dashed salmon;">
<rect x="25" y="25" height="50" width="50" style="cursor: pointer; fill: gold;" onclick="getElementById('box').style.backgroundColor = 'gold';"></rect>
</svg>
<div id="box" style="height: 200px; width: 200px; background-color: skyblue;"></div>
Here is a CodePen.