I have a really big svg file and I want to be able to manipulate it when it's included within an <object>
tag.
If I include it inline it works fine, but it's really big and I want to avoid that.
In my main html
file I include it as follows:
<object type="image/svg+xml" data="/assets/img/banner.svg"></object>
One part of the banner.svg
file is as follows:
<svg id="svgholder" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 2000 768">
<g id="zone-1" data-id="zone-1">
<g id="i551-91" data-name="i551">
<polygon class="cls-6" points="308.74 200.43 310.79 199.4 307.71 197.86 305.65 198.89 308.74 200.43" />
<polygon class="cls-6" points="304.63 202.48 307.71 200.94 304.63 199.4 301.54 200.94 304.63 202.48" />
<polygon class="cls-6" points="300.52 209.68 303.6 208.14 301.54 207.11 300.52 207.62 298.46 206.59 296.41 207.62 300.52 209.68" />
</g>
.....
.....
<g id="zone-2" data-id="zone-2">
<g>
<polygon class="cls-6" points="308.74 197.35 341.62 213.79 308.74 230.23 275.85 213.79 308.74 197.35" />
<polygon class="cls-7" points="308.74 197.35 341.62 213.79 308.74 230.23 275.85 213.79 308.74 197.35" />
</g>
....
</svg>
I want to be able to click on one of those zones (zone-1, zone-2
) and to do something on that click event.
I do it as follows:
$("[id=zone-1]").on("click", function (e) {
e.preventDefault();
// DO SOMETHING
});
That way it works when the svg is included inline in my main html file, but how can I be able to do on click event if I include it with <object>
tag?
Any idea?