I'm using an HTMLObjectElement to display svg graphics as recommended here: https://www.sitepoint.com/add-svg-to-web-page/
The problem is that in javaScript I've done something like:
const objEl = document.createElement( 'object' );
objEl.type = 'image/svg+xml';
objEl.data = 'myGraphic.svg';
objEl.onclick = () => {
console.log( 'I was clicked' );
}
and the onclick event is never fired when I click on it with my mouse.
If I use an img rather than an object, then the click event does fire. Why doesn't the click event work for objects? How can I get click events?
Note, I have also attached objEl.onmouseover and objEl.onmouseout events and they work just fine. It is only the click events that don't work for me.