Reputation: 41
I have a page with multiple SVGs that are embedded like this:
<object data="/path" type="image/svg+xml" id="index"></object>
Each SVG represents a graph and is supposed to execute a function when a node is clicked. So far, I use the following code snippet for a single SVG.
var oTag = document.getElementById('index'); // get object tag
var svgDoc = oTag.contentDocument; // get DOM of SVG
$(svgDoc).on('click', function(event) {...
I there a way to make the code dynamic to handle multiple SVGs?
Upvotes: 0
Views: 58
Reputation: 342
take a look ate this fiddle
https://jsfiddle.net/uttwhh1a/
hope it help
$('.test').each(function(){
$(this).on('click',
function(event) {
alert($(this).attr('value'));
}
);
});
Upvotes: 1