I don't know why, but it works on Chrome and Safari, not in Mozilla.
I have object
html tag that loads svg file. File contains .s0
classes. I want to handle event when you click on that class.
Who knows what is wrong? sry, jsfiddle does not show object
when I tried to paste code there.
<object data="jo.svg" type="image/svg+xml" id="obj"></object>
Code
$(function() {
var a = document.getElementById('obj');
a.addEventListener("load", function() {
// !!!
console.log('this line is not reachable in Mozilla or reached before svg loaded');
var svgDoc = a.contentDocument;
var els = svgDoc.querySelectorAll(".s0");
for (var i = 0, length = els.length; i < length; i++) {
els[i].addEventListener("click", function() {
alert('clicked');
}, false);
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
. I don't know why, but for v1 it does not work. – Clyve